[Dev-C++] Reading file with getc(fp)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: rchavez <rc...@so...> - 2002-04-10 01:48:12
|
Hi,
I am trying to read a text file in a C program. This code runs fine on the
unix C environments I can access but gives a fatal error that removes the
console window in Dev-C++ environment. There are no warnings at compile
time. It is definitely the getc() that causes the trouble because the program
works in Dev-C++ when I use getch() and take input from standard input.
Four questions:
1. How do I make it work with Dev-C++ ?
2. There was lots of talk on getch() and getchar() in the archives but
nothing on getc(). Is getc() no longer ANSI C ?
3. getch() swallows the cntrl-Z so I can't properly terminate using std
input. How do I overcome this when I want to use getch()?
4. Why is EOF cntrl-Z instead of cntrl-D in Dev-C?
Your help will be greatly appreciated and you people are wonderful to give
so much help to the clueless like me on this list!
Rob.
----------------- my code --------------------------
#include <stdio.h>
main()
{
int c;
FILE *fopen(), *fp;
fp = fopen("words.h","r");
while ( (c = getc(fp)) != EOF )
printf("\ngot a char %c",c);
system("PAUSE"); /** added this for Dev-C++ **/
return 0;
}
|