M
Morris Dovey
broli said:I cannot understand why the program goes into infinite loop after the
file is printed on the screen.
char c;
c = fgetc(fp);
if(c == EOF)
Vatiable c must be an int.
broli said:I cannot understand why the program goes into infinite loop after the
file is printed on the screen.
char c;
c = fgetc(fp);
if(c == EOF)
broli said:After changing to int, Im still getting an infinite loop -
broli said:I cannot understand why the program goes into infinite loop after the
file is printed on the screen.
#include<stdio.h>
int main(void)
{
FILE *fp;
char c;
fp = fopen("sample.dat", "r");
if(fp == NULL)
{
printf("Cannot open the file\n");
return 0;
}
while(1)
{
c = fgetc(fp);
if(c == EOF)
EOF is not a value that fits in a char.
c should be an int, not a char.
broli said:I use TC 2.01 on win xp and to be honest it has given me many
problems. I want to use a different and easier complier, I have looked
around but cannot find one.
Yes now I recall reading this in K & R 2. Strangely I found this wrong
approach( char c = EOF) being used in many online tutorials.
Yes now I recall reading this in K & R 2. Strangely I found this wrong
approach( char c = EOF) being used in many online tutorials.
After changing to int, Im still getting an infinite loop -
Morris said:Hmm - did you re-compile and re-link after making the changes?
broli said:I use TC 2.01 on win xp and to be honest it has given me many
problems. I want to use a different and easier complier, I have looked
around but cannot find one.
Try MinGW, Cygwin, Borland's free command line compiler or Microsoft's
Express 2008, or lcc-win32 or PellesC etc.
You are spoiled for choice!
I use TC 2.01 on win xp and to be honest it has given me many
problems.
I don't have XP, but use TC3 under 95, 98, and ME without problem
- but much prefer to boot up Linux and use gcc.
Actually, I don't think you'll find anything very much easier to
use than your Turbo C package. I think version 3 is available for
free download if you think it might solve any of your problems.
My favorite trick is making changes in an edit window, then
compiling, linking, and running the program without having saved
my changed source file.
broli said:lcc-win32.. is it freely available on jacob navias website ?
After changing to int, Im still getting an infinite loop -
santosh said:Try MinGW, Cygwin, Borland's free command line compiler or Microsoft's
Express 2008, or lcc-win32 or PellesC etc.
You are spoiled for choice!
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.