I'm stuck on the initial part of the Mario pset. I continue to get the same error message: mario.c:6:1: error: expected identifier or '(' { ^ I understand that it has something to do with the curly brackets/initiation of the function, but I do not understand what I am going wrong. I've literally copy pasted code from online and I still get the same error message. Can you help me out? Here is my code:

// Pset1_MarioMore

#include <stdio.h>
int main(void);

    int height;
    height = get_int("Enter integer between 2-23: ");
    while (height < 0 || height > 23);

enter image description here


No worries, it's a common mistake for new programmers. A semicolon ends a line of code or a code block. In this case, you have placed a semicolon after the main signature code:

int main(void);

By adding a semicolon there, it identified this as a signature line and not the main() code block. You'll learn more about this later. Just delete the semicolon and this error will disappear.

No guarantees that there aren't other issues, but that'll be for a new question. ;-)

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

  • One of the techniques I use to avoid this is to end the line with the {, rather than have it in the next line. As in int main(void) {, all on the same line. This prevents one adding extraneous semicolons! – Tim Aug 9 '18 at 1:44
  • True, but code is much easier to read when paired curly braces are indented the same amount and everything inside gets an additional indent. It makes the code so much easier to read 6 months later when you have to come back and modify or debug it. – Cliff B Aug 9 '18 at 5:57
  • I suppose that’s a fair point. I use an editor with bracket matching built in, which helps. I also coded in JavaScript and node.js before C, which I expect influenced my usage. I suppose for beginners, this mistake is much rarer (and easier to solve) than bracket issues. – Tim Aug 9 '18 at 11:34

You must log in to answer this question.

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