Sunday, August 2, 2009

How do I enter an EOF character using keyboard in Turbo C.?

I have the following code:


--------------------------------------...


FILE *f1;


char c;


f1 = fopen("INPUT","w");


while((c=getchar()) != EOF)


putc(c,f1);


fclose(f1);


--------------------------------------...





FYI - This is not the full program. The only statements before this is the library function(stdio.h) and main.





When the program hits the loop, i am able to enter characters, but I am not able to terminate the loop.





I searched the web and found that the value of EOF is -1 or above 255. But if I enter -1, the putc statement is writing '-' to the file, then '1' to the file as 2 separate values.





I searched further and found I could terminate the loop by entering ctrl+z, ctrl+d, or ctrl+c. The first 2 did not work and ctrl+c terminated the execution of my entire program.





Does anyone know how to solve problem?

How do I enter an EOF character using keyboard in Turbo C.?
Try f6+enter





It works for copy con command in command line.
Reply:Alt+C is working in this mattar.
Reply:well it depends on the level of your quantin compacity accelator is it high or is it low plz write back when you find out
Reply:If you open the file on a TEXT stream the End of File character is CTRL Z





If its on a binary stream the End of File is CHR(0) that is NULL character.


No comments:

Post a Comment