Mail Archives: djgpp/1997/06/12/18:20:43
> >This will output a text file to the screen, like type.exe:
> >
> ><-------------------------BEGIN----------------------------->
> >
> >#include <stdio.h>
> >
> >main()
> >{
> > FILE *f;
> > char ch;
> > f=fopen("c:/files/sample.txt","rt");
> > /* read a char from the file */
> > fscanf("%c",&ch);
^^
> > /* is it the end of the file yet? */
> > while(c!=EOF){
^
> > /* write the char to the screen */
> > prinf("%c",ch);
> > /* read another character */
> > fscanf("%c",&ch);
^^
> > }
> > /* close the file */
> > fclose(f);
> > return 0;
> >}
> Have you tested this piece of code before posting here?
Do you have one of those funny compilers that thinks that variable
c is undeclared, and that fscanf needs its first argument to
be a file pointer? ;) Or does it say use getch instead of fscanf.
Andrew
- Raw text -