To whoever is reading this,

I have been working on the caesar cipher and i wrote a few stuff on gedit. I am not sure if this is correct or waaaay of. Please help me

Thanks and have a great day :)

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

int main(int argc, string argv[]);
string k = argv[1];
int k = atoi(argv[1]);

    for (int i = 0, n = strelen(p); i < n; i++)
        printf("%c", p[i];
    return 0;
    ci = (pi + k) % 26
  • 1
    Also, you should compile and run it and see what the results are. If it doesn't compile, start working through the errors in order (one error can often cause more errors later.) Once it compiles, then run it with test data and see if the results are correct. If not, start tracking down the errors in the logic.
    – Cliff B
    Jun 26, 2015 at 18:05

1 Answer 1

  1. You did strlen(p) but never initialized (created) a variable called "p". The compiler will have no idea what you're talking about there.

  2. For me at least, I wasn't able to directly use the formula c[i] = (p[i] + k) % 26 in my Caesar cipher code. You're going to have to think a little bit harder about the various situations that letters can be presented to you. For example, "A" and "a" have different ASCII codes. Also, be sure to consider how your code will handle " " (blank spaces). If/else statements will be huge in making this Caesar cipher.

  3. The ciphers are a bit challenging, but it's a very fulfilling pset to complete, so keep it up! Good luck!

You must log in to answer this question.

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