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: 12 Jun 1997 08:56:52 GMT Organization: Power Up Lines: 52 Message-ID: <5nodkk$h34$1@grissom.powerup.com.au> References: Reply-To: phreadd AT powerup DOT com DOT au NNTP-Posting-Host: ts3406.powerup.com.au Mime-Version: 1.0 Content-Type: Text/Plain; charset=US-ASCII To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk In article , jamesj AT wsunix DOT wsu DOT edu says... > >I have recently downloaded a copy of djgpp v2.01 and have been using it >with the rhide IDE. I have learned how to write and compile basic >programs but have been working for 3 days on getting my programs to read >txt files from a dos diretory. This will output a text file to the screen, like type.exe: <-------------------------BEGIN-----------------------------> #include main() { FILE *f; char ch; /* open the file, "rt" means "read, text" */ /* if it doesn't work, it might require double */ /* slashes. ie. "c://files//sample.txt" */ 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; } <------------------------------END--------------------------> Hope this helps. -- | David Orme <>< | | | phreadd AT powerup DOT com DOT au | "Striving for Excellence" | | powerup.com.au/~phreadd | |