so the above is my code and here is the output i am getting after compiling the program. I can't understand why i is always zero no matter what input i give. please help me out as it might be a simple thing for you but i have wasted two days to find a solution and still no success.
1 Answer
Hi and welcome to the forum. A couple of procedural things before we get to the question:
- I assume this question supersedes the original question. Be sure to delete the original. For future reference, there is an edit option at the bottom of questions which would be the perfect approach in this case.
- Pasting the actual code is usually better than screen shots. If someone wants to test out your code, they would not have to re-type it. Your question will get better attention that way. (+1 for improving the look of the code by any means.)
- To easily format code that has been pasted into a question (or answer, for that matter), select the code you pasted then click the
{}
in the formatting bar. Ta-da, formatted code.
Now, to the heart of the matter. What is argv[1]
in this command ./a.out caesar.c 4
? According to man atoi
:
The atoi() function converts the initial portion of the string pointed to by nptr to int.
In this case there is no "integer" portion of argc[1]
, thus it returns 0. The program is working properly because as called, argv[1]
is caesar.c
and atoi[caesar.c]
returns 0.
And a warning: The checker (check50) and submit (submit50) software will use make
to compile. If your program does not compile with make
it will not pass.
-
so how do i convert the key to an integer? i am still confused, how do i get to see what is my key and if argv[1] is the caesar.c then what is argv[0] in that case? Commented Aug 30, 2018 at 1:26
-
finally did it !!! so happy, now i understood what i was doing wrong, i used the command from cs50 make caesar and then ran the following code ./caesar 1 and it worked just fine. Phew! now i can get on with the rest of the code. thanks a lot dino. Commented Aug 30, 2018 at 1:48