ramcha
ramcha

Reputation: 11

Unexpected syntax error from MingW compiling a simple C program

Complete Novice alert :

#include<stdio.h>

int main()

{ puts("C Rocks!");
  return 0;
} 

When compiled with MinGW, it shows two errors:

  1. syntax error near unexpected token ( in the beginning
  2. and int main ()

What is wrong with the code?

Upvotes: 1

Views: 1728

Answers (3)

Kbam7
Kbam7

Reputation: 334

I was also having this issue. Check for illegal characters in the path name such as spaces or brackets. Your code looks correct so the issue isn't there. If all else fails, go back to the basics. Make sure you're actually using "gcc file.c -o file.exe" to output the correct file. For some reason, i completely forgot to use 'gcc', even though I had been using MinGW for over month.

Upvotes: 1

Leonardo Miguel
Leonardo Miguel

Reputation: 11

There's nothing wrong with your code. Is the first time you compile something? It seems to be a problem with the MingW. It can be spaces in the path, for example.

To avoid some beginner problems, you can use an IDE, like Dev-C++(http://www.bloodshed.net/devcpp.html), as it can compile C and C++ code.

Upvotes: 0

Dayal rai
Dayal rai

Reputation: 6606

Install mingw in a path without spaces.MinGW will experience problems with such paths. Thus, i strongly recommend that you do not install MinGW in any location with spaces in the path name reference; i.e. you should avoid installing into any subdirectory of "Program Files" or "My Documents", or the like.

Upvotes: 0

Related Questions