delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/12/18:20:43

From: Andrew Crabtree <andrewc AT typhoon DOT rose DOT hp DOT com>
Message-Id: <199706122220.AA008974031@typhoon.rose.hp.com>
Subject: Re: writing a program that reads .txt files
To: djgpp AT delorie DOT com
Date: Thu, 12 Jun 1997 15:20:31 PDT

> >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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019