Results 1 to 4 of 4
hai,
i am try to compile this program
include <stdio.h>
void main()
{
FILE *fopen(), *fp;
int c ;
char filename[40] ;
printf(“Enter file to be displayed: “);
gets( filename ...
- 05-16-2007 #1Just Joined!
- Join Date
- May 2007
- Posts
- 4
files program: error :stray
hai,
i am try to compile this program
include <stdio.h>
void main()
{
FILE *fopen(), *fp;
int c ;
char filename[40] ;
printf(“Enter file to be displayed: “);
gets( filename ) ;
fp = fopen( filename, “r”);
c = getc( fp ) ;
while ( c != EOF )
{
putchar(c);
c = getc ( fp );
}
fclose( fp );
}
i am getting following errors
cc fil2.c
fil2.c:1: error: syntax error before '<' token
fil2.c:9: error: stray '\226' in program
fil2.c:9: error: stray '\128' in program
fil2.c:9: error: stray '\156' in program
fil2.c:9: error: syntax error before "file"
fil2.c:9: error: stray '\226' in program
fil2.c:9: error: stray '\128' in program
fil2.c:9: error: stray '\156' in program
fil2.c:9: warning: conflicting types for built-in function 'printf'
fil2.c:9: warning: data definition has no type or storage class
fil2.c:10: warning: parameter names (without types) in function declaration
fil2.c:10: warning: data definition has no type or storage class
fil2.c:12: error: stray '\226' in program
fil2.c:12: error: stray '\128' in program
fil2.c:12: error: stray '\156' in program
fil2.c:12: error: stray '\226' in program
fil2.c:12: error: stray '\128' in program
fil2.c:12: error: stray '\157' in program
fil2.c:12: error: `r' undeclared here (not in a function)
fil2.c:12: error: initializer element is not constant
fil2.c:12: warning: data definition has no type or storage class
fil2.c:14: error: initializer element is not constant
fil2.c:14: warning: data definition has no type or storage class
fil2.c:16: error: syntax error before "while"
fil2.c:19: error: redefinition of 'c'
fil2.c:14: error: previous definition of 'c' was here
fil2.c:19: error: initializer element is not constant
fil2.c:19: warning: data definition has no type or storage class
fil2.c:20: error: syntax error before '}' token
fil2.c:22: warning: parameter names (without types) in function declaration
fil2.c:22: warning: data definition has no type or storage class
fil2.c:23: error: syntax error before '}' token
plz help me where i made mistake how resolve this
thanks in advance
- 05-16-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Remove the declaration of *fopen().
This line:
should be:Code:FILE *fopen(), *fp;
RegardsCode:FILE *fp;
- 05-16-2007 #3Just Joined!
- Join Date
- May 2007
- Posts
- 4
hi Franklin52,
i removed the declaration but still i am getting same error
- 05-16-2007 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Hi,
Did you cut and paste the code from a doc or html file?
You have some invalid characters in your file, try this:
And place your code within code blocks next time, that makes it easier to read.Code:#include <stdio.h> void main() { FILE *fp; int c; char filename[40]; printf("Enter file to be displayed: "); gets( filename ); fp = fopen( filename, "r"); c = getc( fp ); while ( c != EOF ) { putchar(c); c = getc ( fp ); } fclose( fp ); }
Regards


Reply With Quote