Brainlag
  1. Library
  2. Debugging
  3. C

';' expectedWhat does "';' expected" mean?

A message like `;' expected or `}' expected means the compiler wanted a symbol that is not there. The real mistake is often on the line above the one it names.

C5 min

What the compiler is telling you

Output
main.c(5): `;' expected
    printf("lives %d\n", lives);
    ^~~~~~

The compiler was reading your code and reached a spot where only one symbol made sense, here a ;, but found something else. The quotes around the symbol are the compiler's style: the thing it wanted is between the backtick and the apostrophe.

The usual suspects:

  • `;' expected: a statement on the line above does not end with a semicolon.
  • **}' expected**: a {` was opened and never closed. The compiler only finds out at the end of the file.
  • **)' expected**: a bracket left open in a call or an if`.

How to find it

The line number is where the compiler noticed, not always where you made the mistake. For a ;, look at the end of the line just above the marker. For a }, the line number is often the last line of the file: count your braces. Every { needs a partner, and good indentation makes the missing one stand out. Fix the first error, then run again; one missing symbol can cause a pile of later errors.

Run it: the line above

Press Run and read the error from the bottom up.

main.c to run
#include <stdio.h>

int main(void) {
    int lives = 3
    printf("lives %d\n", lives);
    return 0;
}

A shop that never closes

This prints the items a player can afford with 250 coins. It does not compile. Read the message and fix it so it prints the two items.

exercise_1.c to run
#include <stdio.h>

int main(void) {
    int prices[4] = {300, 120, 90, 400};
    int coins = 250;
    for (int i = 0; i < 4; i++) {
        if (prices[i] <= coins) {
            printf("item %d costs %d\n", i, prices[i]);
    }
    return 0;
}

Code editor. Press Control or Command plus Enter to run the code. Tab indents; to move focus out of the editor, press Escape and then Tab.