EOF question

C

CBFalconer

Kenneth said:
.... snip ...

It could be a bug in Windows and/or the C runtime.

Change the printf() line to read:

printf("aefore newline\nafter newline %ld\n",nc);

On Windows 98, with MSVC 6.0a (compiler version 12.00.8168) typing
"foobar" newline Ctrl-Z newline, I get:

foobar
after newline 7

Note that everything in the printf() prior to the newline is gone.

On Windows XP:

foobar
^Z
before newline
after newline 7

And the program has not yet exited. I need to press Enter one
more time to get the program to exit.

It's not W98 FE. Under that, and DJGPP 2.03, gcc 3.3.1:

[1] c:\c\junk>gcc junk.c

[1] c:\c\junk>a
Bloody nonsense
^Z
16

[1] c:\c\junk>type junk.c
#include <stdio.h>

int main(void)
{
long nc;

nc = 0;
while (getchar() != EOF) ++nc;
printf("%ld\n", nc);
return 0;
}
 
N

newby2c

Kenneth Brody said:
It could be a bug in Windows and/or the C runtime.

Change the printf() line to read:

printf("aefore newline\nafter newline %ld\n",nc);

On Windows 98, with MSVC 6.0a (compiler version 12.00.8168) typing
"foobar" newline Ctrl-Z newline, I get:

foobar
after newline 7

Note that everything in the printf() prior to the newline is gone.

On Windows XP:

foobar
^Z
before newline
after newline 7

And the program has not yet exited. I need to press Enter one more time
to get the program to exit.

I get the same results as you except the program terminates after <ctrl-z>.

newby2c
 

Ask a Question

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.

Ask a Question

Similar Threads

question 20
Question about the getchar() and eof !!!... 25
basic c i/o and EOF 1
basic c i/o and EOF 28
EOF in Windows 11
What's wrong ? 21
Pass an EOF instead of pressing enter 1
Pass an EOF before pressing enter 9

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top