Mail Archives: djgpp/1997/06/12/14:17:41
In article <Pine DOT OSF DOT 3 DOT 95 DOT 970611151232 DOT 6412A-100000 AT unicorn DOT it DOT wsu DOT edu>,
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 <stdio.h>
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 | |
- Raw text -