RE: [Dev-C++] Reading file with getc(fp)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <igo...@po...> - 2002-04-10 07:37:45
|
Hi,
For reading files try using fgetc instead of getc
and your program should work OK.
Regards
Igor Pierscinski
-----Original Message-----
From: rchavez [mailto:rc...@so...]
Sent: Wednesday, April 10, 2002 3:48 AM
To: dev...@li...
Cc: rc...@so...
Subject: [Dev-C++] Reading file with getc(fp)
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;
}
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|