How Do You Troubleshoot the C Program Error “error: expected ‘;’ before string constant”?

Problem scenario
You try to compile a program with "gcc nameofprog.cc".  You get this output: "foobar.cc.:55:error: expected ';' before string constant"

What do you do to compile your program?

Solution
Go to line 55 of foobar.cc.  If there is a printf command, be sure that the thing to be printed is surrounded by parentheses.  Here is an example of a line that will cause the problem:
   printf "This is a test";

Here is an example of a printf command with proper syntax:
   printf ("This is a test");

Leave a comment

Your email address will not be published.