0

I can copy verbatim what my instructor types in and check it twice. when i go to compile the code it tells me hi.c:4:1: error: expected identifier or '(' { ^ 1 error generated. I have tried deleting my curly brace and adding the parenthesis, sometimes if I put them both it'll work. im also being told to put a semicolon after my int main(void) which im pretty sure isnt necessary
heres the code:

#include <stdio.h>

int main(void);
{
    string s = "HI!";
    
    printf("%s\n", s);
}

should be simple right? well not for me please help. what am i doing wrong?

1
  • that didnt come out the way i typed it but im sure you understand
    – Aamon Van
    Commented Feb 23, 2021 at 0:24

1 Answer 1

1

It's a very common newbie mistake.

int main(void);

The semicolon at the end of the line ends main. Remove it.

The correct syntax of a program is this:

// all include statements first
#include ...

int main(void)
{   // opening curly brace here.  Note there was no semicolon before this.

    // code goes between curly braces.  

}   // final curly brace ends main. 

BTW, string is a CS50 thing. You'll also need #include <cs50.h>

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 .