delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/13/16:49:22

From: phreadd AT powerup DOT com DOT au (David Orme)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: writing a program that reads .txt files
Date: 13 Jun 1997 11:23:57 GMT
Organization: Power Up
Lines: 43
Message-ID: <5nrakd$10u$1@grissom.powerup.com.au>
References: <Pine DOT OSF DOT 3 DOT 95 DOT 970611151232 DOT 6412A-100000 AT unicorn DOT it DOT wsu DOT edu> <5nodkk$h34$1 AT grissom DOT powerup DOT com DOT au>
Reply-To: phreadd AT powerup DOT com DOT au
NNTP-Posting-Host: ts1514.powerup.com.au
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Sorry, actually there were a few syntax errors.

Lines 14, 23: fscanf("...
   should be: fscanf(f,"...

Line 19:      c!=EOF
   should be: ch!=EOF

Line 20:      prinf(...
   should be: printf(...


When I compiled this program (at request) I had a problem with the EOF 
constant. A quick change to make it use "feof(f)" instead gives the 
following correct, working and tested code:


#include <stdio.h>

main()
{
  FILE *f;
  char ch;

  f=fopen("c:/autoexec.bat","rt");

  fscanf(f,"%c",&ch);
  /* while not the end-of-file of f */
  while(!eof(f)){
    printf("%c",ch);
    fscanf(f,"%c",&ch);
  }

  fclose(f);
  
  return 0;
}

-- 
|  David Orme                 <><   |                             |
|  phreadd AT powerup DOT com DOT au           |  "Striving for Excellence"  |
|  powerup.com.au/~phreadd          |                             |

- Raw text -


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