file io - syntax error near unexpected token '(' in C -


i'm getting confusing error message. i'm running mingw on windows xp 32-bit. when attempt compile following code, error message "./hello.c: line 4: syntax error near unexpected token '('". line 4 @ int main(...), can't figure out unexpected token "near '('". i've tried using int main(void), same message. however, if compile without "char string..." , "data = fputs(...)" , have read given text file, compiles without issue.

what i'm trying accomplish read file filename given external source, i.e. php. i'm going working apache module parser i've made, hence call php, wanted fool around , build template code work before got part.

#include <stdio.h> #include <stdlib.h>  int main (void) {     file *fp;     //char string = "jd";    commented out     char data;     //printf("type in filename:   "); commented out     //scanf("%s", &argv);  commented out      if(argc >= 2)     {         fp = fopen("sample.txt", "r"); //switched reading given file     }     while((data = getchar()) != eof)     {         fgets(data, sizeof(data), fp);         // data = fputs(string, fp);     }      if (fp==null) /* error opening file returns null */     {         printf("could not open player file!\n"); /* error message */         return 1; /* exit failure */     }     /* while we're not @ end of file */     while (fgets(data, sizeof(string), fp) != null)     {         printf(data); /* print string */     }      fclose(fp); /* close file */     return 0; /* success */ } 

okay, tried writing simple "hello world" program, i'm still getting same error message makes me think error message isn't being caused code @ all.

#include <stdio.h>  int main(void) //still getting syntax error before unexpected token '(' {     printf("hello, world!");     return 0; } 

your line

int main (int argc, char *argv) 

is wrong. must be

int main (int argc, char *argv[]) 

or

int main (int argc, char **argv) //less common, though 

and line

char string = "jd"; 

should be

const char *string = "jd"; 

also, don't get

scanf("%s", &argv); 

why read into argv?


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -