I won't post my code, because, as far as I could tell, it works fine, but I keep on getting this when I run check50 and I don't know know exactly what it means or how to fix it. My code runs perfectly whatever input I give it, as far as I know.
:) caesar.c exists.
:) caesar.c compiles.
:( encrypts "a" as "b" using 1 as key output not valid ASCII text
:) encrypts "barfoo" as "yxocll" using 23 as key
:) encrypts "BARFOO" as "EDUIRR" using 3 as key
:) encrypts "BaRFoo" as "FeVJss" using 4 as key
:) encrypts "barfoo" as "onesbb" using 65 as key
:( encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key output not valid ASCII text
:) handles lack of key
:) handles non-numeric key
:) handles too many arguments
I just ran my code again and realized that when it runs it sometimes adds another character after the output. Maybe that's what the error is? Thanks for the past answers. They really helped.

Hi, here's my code. Maybe it will help.

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

int main(int argc, string argv[])

    //stop if more than one key and if not a digit
    if (argc != 2)
        printf("Usage: ./caesar key\n");
        return 1;
    for (int n = 0; n < strlen(argv[1]); n++)
          if (isalpha(argv[1][n]))
          printf ("Usage: ./caesar key\n");
          return 1;

int key = atoi(argv[1]);

    //ask user for string
    string ptxt = get_string("Plaintext:");

    //initialize the char ctxt to be as long as the string ptxt
    char ctxt [strlen(ptxt)];

    //run program, but keep uppercase/lowercase and non alphabetical characters
    for (int i = 0; i < strlen(ptxt); i++)
        if (isalpha(ptxt[i]))
            if (isupper(ptxt[i]))
                ctxt[i] = (((ptxt[i] - 65 + key) % 26) + 65);
            else if (islower(ptxt[i]))
                ctxt[i] = (((ptxt[i] - 97 + key) % 26) + 97);
            ctxt[i] = ptxt[i];
    //print the ciphertext
    printf("ciphertext: %s", ctxt);

    return 0;


1 Answer 1


Short answer. If check50 says it's giving incorrect results, it really is giving incorrect results. Check50 has been thoroughly tested and run millions of times. It's extremely rare to find a bug in check50. If it says that something is wrong, believe it and start looking for a flaw in your code.

So, my recommendations are these:

  1. Go to the link given in the check50 results and look at the detailed results for the failed tests.
  2. rerun the failing tests yourself on your code and see what happens.

If you can't resolve the issues, post your code and someone will take a look at it and point you in the right direction.

You must log in to answer this question.

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