I'm getting a syntax error that's confusing me beyond belief. I'm using MinGW on Windows XP(32-bit), and Notepad++ for a text editor.
"Syntax error before unexpected token '('"
Originally, I thought it may have been something in the code I was trying to compile, so I wrote a simple "hello world" program, but I'm still getting it even though '(' is right where it should be.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fp;
char data;
if(argc >= 2)
{
fp = fopen("hello.txt", "r+");
}
if (fp==NULL) /* error opening file returns NULL */
{
printf("Could not open player file!\n"); /* error message */
return 1; /* exit with failure */
}
while(fgets(data = getchar()) != EOF)
{
fgets(data, sizeof(data), fp);
}
/* while we're not at end of file */
while (fgets(data, sizeof(string), fp) != NULL)
{
printf("%s", data); /* print the string */
}
fclose(fp); /* close the file */
return 0; /* success */
}
//hello world source code below
#include <stdio.h>
int main(void)
{
printf("Hello world!");
return 0;
}