0

Ok so i just started caesar and i don't know whether I'm headed in the right direction or not, if not i just need someone to point me the right way,and yes i have seen the walkthrough.

so heres my code:

int main(int argc, string argv[]){

    if(argc != 2)
    {
        return 1;
    }
    else
    {
        return 0;
    }

}

and i heres what i get when its run:

jharvard@appliance (~/Dropbox/pset-2): make caesar
clang -ggdb3 -O0 -std=c99 -Wall -Werror    caesar.c  -lcs50 -lm -o caesar
jharvard@appliance (~/Dropbox/pset-2): ./caesar awesom
jharvard@appliance (~/Dropbox/pset-2): ./caesar
jharvard@appliance (~/Dropbox/pset-2): ./caesar foo bar
jharvard@appliance (~/Dropbox/pset-2): ./caesar
jharvard@appliance (~/Dropbox/pset-2): ./caesar foo
jharvard@appliance (~/Dropbox/pset-2):
2
  • so nothing really happens, anyone know if I'm headed the right way or not?? Aug 6 '15 at 10:59
  • If you want to see the exit code of a program in the terminal you have to run echo $? after the program has finished.
    – wallek876
    Aug 6 '15 at 11:20
1

Well your program is correct, in the sense that it doesn't have any compiling errors, but it doesn't do anything. It just checks whether the user gave 2 arguments or not. You are correctly returning 1 in case he provides any other number of arguments except from 2 (you can use echo $? to see this) but that is not all the program should do.

Also you should say something when the user inputs the wrong number of arguments, something like printf("Usage: ./caesar key"); and then return 1.

Also you must continue the code to do something when the correct number of arguments is given. You need to implement caesar that is.

You must log in to answer this question.

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