0

I am just starting the caesar problem set, and I have already run into a problem. Just to start off with, I wanted to create a clause where the program would output 'error' if argc was not equal to 2, and convert the string argv into an integer and then printf the integer as a sanity check. Here is my code so far:

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

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

{
if (argc != 2)
    printf("Error\n");

int atoi (string argv);

printf("%i\n", argv);
}

However, I get the following error when trying to compile the program:

caesar.c:7:1: error: expected identifier or '('
{
^
1 error generated.
make: *** [caesar] Error 1

This seems very vague, and the other answers I've looked at on here don't apply to what I've done. Any help about how to resolve this error would be much appreciated.

By the way I'm new to programming and a complete noob at the command line arguments after main, so it might be something really obvious I'm missing.

Thanks, Dan

1
  • Ah! Glad to know I’m following in the footsteps of many before me. Thanks very much for your help Feb 5 '18 at 21:44
2

... so it might be something really obvious I'm missing.

It is. It's also arguably the single most common error made by brand new programmers. Everyone does it once or twice in the beginning! ;-)

When creating main or a function, the structure looks like this:

int main(int argc, string argv[])
{
    // all program code
}

You've inserted a semicolon at the end of the main signature line. A semicolon here means that the signature line is only there to tell the compiler that the actual function code is somewhere else, but to remember that it exists. It also means that the code that follows isn't part of this function. You'll learn about this later.

That semicolon should NOT be there. Remove it.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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