C Study Guide

St. Gabriel's College


Fixing Errors

Sometimes your program works perfectly. However, usually you will have to fix errors before your program will run. This lesson will teach you how to fix errors.

I have SO MANY errors!

Don't worry! Sometimes if you have one error at the beginning of the program, the compiler will panic and tell you that you have many errors. You should start at the top of the program, and fix one error at a time. Usually, this will make the other errors go away by themself.

Warnings vs. Errors

When you compile your program, there are two ways the compiler will tell you if there is a problem:

We will talk about both kinds of problems in this lesson, but it is good to know the difference.

Common errors and warnings

If you are having problems with an error, check if you are getting one of these messages:

error: expected ',' or ';'' before '*something*'

This error means you forgot a semicolon. The 'something' part is usually on the line AFTER the missing semicolon.

error: '*something*' undeclared (first use in this function)

This usually happens because you spelled something wrong. It means you are talking about a variable that you never created.

error: expected declaration or statement at end of input

This means you have an open brace "{" with no closing brace "}". Check your if-else statements, loops, etc. and try to find where there is a missing brace.

error: missing terminating " character

This means you started a string with " but didn't end it. Check your printf() functions and anywhere you talk about strings.

error: conflicting types for 'something'
error: previous implicit definition of 'something' was here

These can both happen if you use a function before you define it or declare it. You can fix this by declaring your functions at the beginning of your program, like this:

int function(int a);

This is a good idea, even if you aren't getting errors.

warning: comparing pointer to an integer without a cast

There are many reasons this could be happening. If you aren't using pointers anywhere, check to see if you are using your string functions properly. For example, this will give you an error:

char word[1000];
strcpy(word, "chalkboard");

However, this will fix it:

char word[1000];
strcpy(&word, "chalkboard");

Also, look at where you are using the NULL value, as that is treated like a pointer.

warning: unused variable ‘*something*’

This means you created a variable and then never used it. This shouldn't cause any real problems when you run the program, but you might want to check why you didn't use it.

If you are getting a message that isn't on this page, let me know and I can add it in!