1
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>


int main (int argc, string argv[])
{   
if (argc != 2)
{
    printf("Usage /caesar.c <key> ");
    return 1; 
}
int key,e;
key = atoi(argv[1]);
string pt;
pt = GetString(); 
string et;
et = pt;
for (int i=0; pt[i] != '\0'; i++)
{
    if(isalpha(pt[i]))
    {
        if (islower(pt[i]))
        {
            e = (((pt[i] - 96) + key)% 26) + 96; 
            et[i] = (char)e;
        }  
        if (isupper(pt[i]))
        {
            e = (((pt[i] - 64) + key)% 26) + 64; 
            et[i] = (char)e;
        }

      }

   }
    printf("%s", et);

return 0; 
 }

The output is the same as asked by the program but still shows an error on checking.

2 Answers 2

1

You need to print a linefeed char '\n' after the chipertext.

So it should be printf("%s\n", et); instead of printf("%s", et);

If this solves your problem, please click the check mark to accept the answer.

0

maybe the error is due to the statement (et=pt;) you can't just assign one string to another one. I had done the same mistake and errors occurred due to it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .