0

After, trying to add 1 to j, so I can only encrypt characters and not non alphas I am still having issues. Really getting stuck on this and have outsourced a lot online from what other people have done but no matter what I still have the same issue. This is my for loop that I am having issues with.

for( i = 0, j = 0; i < n; i++, j++){
             if(j == k){
                 j = 0;
             }
              keyVal = shift(key[j]);
              int c = pretext[i] + keyVal;   
              if(isupper(pretext[i]) && (c > 'Z') ){
                      c = c - 26;
                  j++;
              }
              else if(islower(pretext[i]) && (c > 'z') ){
                      c = c - 26;
                  j++;
              }
              pretext[i] = c;
       }

0

It's still incrementing j in the for loop, in other words, for EVERY char, in addition to incrementing inside the loop.

for( i = 0, j = 0; i < n; i++, j++){
5
  • I realize that, but I am trying to get help on how to fix it.
    – user24000
    Aug 1 '19 at 21:27
  • Just remove the j++ from the for loop statement. That'll cure the j incrementing problem. That's not to say that there are or aren't other issues. You're still overthinking things!
    – Cliff B
    Aug 1 '19 at 23:19
  • Yeah I definitely am but I'm just stuck because I feel like I've tried everything.
    – user24000
    Aug 2 '19 at 3:58
  • I was able to solve it, thank you. Took some time but jesus the solution was so simple.
    – user24000
    Aug 7 '19 at 22:36
  • "KISS".... search the forum and you'll understand. ;-)
    – Cliff B
    Aug 7 '19 at 22:41

You must log in to answer this question.