r/cs50•
69BigPimpin420

Pset 2 Caesar: Check succeeds but when I try to run the same code as the check, I get a different output.

Spoilercaesar

So I just spent a couple hours working on caesar, and when I do the check50 command, everything is green indicating it's correct, but when I run the line "encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key" instead of getting that answer I get "iadxpemktqxxa" without any commas, spaces or the exclamation mark. My for loop looks as follows:

 for (int n = 0, p = strlen(plain); n < p; n++)
 {
    if (isalpha(plain[n]))
    {code goes here
      }
     else
      {
        printf("%c", plain[n]);
       }
  }

I thought in this instance the for loop would check if it's alpha, and if it isn't to just print the n'th character of plain. Very confused as to why I'm getting "iadxpemktqxxa" as if there were only letters entered.

Any help would be appreciated.

Posted Jun 16, 2017, 7:19 PM UTC

12
Loading comments…