EOF question

N

newby2c

RoSsIaCrIiLoIA said:
Here in windows xp <ctrl-z>==EOF so if I push some chars <ctrl-z> and
'\n' the prog print the correnct number of char (less the last '\n').
I think you could resolve your problem if you write in the code
printf("%ld\n\n", nc); /* note \n\n */
and use <ctrl-z> for end.

Thanks R...,

I just tried that. Still no good. Damn this is frustrating.

newby2c
 
E

Emmanuel Delahaye

newby2c wrote on 10/08/04 :
Hi Emmanuel,

If you mean to hit <ctrl-z> *and* <enter> at the *same time*, I tried that.
Unfortunately, that did not work either.

No. Hit them in sequence.
<ctrl-z>
then
<enter>
 
R

RoSsIaCrIiLoIA

Thanks R...,

I just tried that. Still no good. Damn this is frustrating.

newby2c
yes, this seems goes ok in Windows95

#include <stdio.h>

int main(void)
{
long nc;

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

CBFalconer

newby2c said:
I just tried your suggestion. No good.
Ran prog.
typed Hello, my name is newbyc (then ctrl-z on the same line).
Then hit enter.
Prog. terminates with DOS window still open (I added getchar();).
See code below:

No, line, enter, ctl-z, enter.
 
N

newby2c

CBFalconer said:
No, line, enter, ctl-z, enter.

Thanks again.
Ran prog. Typed line. Hit <enter> (the caret moved to new line).
Hit <ctrl-z>. Prog. terminates.
Never had a chance to hit <enter>.
This was the program in it's original form (without getchar();).
With the getchar(); in place just before the return 0; I type some words,
hit <enter>, then hit <ctrl-z>, (prog. does *not* terminate), lastly I hit
<enter>. The prog. terminates, but there is still no output.

newby2c

newby2c
 
N

newby2c

Joona I Palaste said:
No, he meant first hit <ctrl-z> and then hit <enter>.

Thanks Joona,

I had already tried that and it did not work to which I posted in an earlier
message. That is why I thought hit meant to hit them together.

newby2c
 
N

newby2c

RoSsIaCrIiLoIA said:
yes, this seems goes ok in Windows95

#include <stdio.h>

int main(void)
{
long nc;

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

That's it! It worked! I added the two newline (\n\n) characters to the
*front*, before the long integer (as seen above). I ran the program. Typed
in "this is a test" (without quotes). Hit <ctrl-z>. The number 14 appears,
and the prog. terminates. Excellent!! I don't know *why* it works, but it
does. Anyway, this is a good one for the books.

Thanks R...!!! Thank you all for your input. Now if someone could explain
why this needs to be done this way, I would have gained a very valuable
lesson.

newby2c
 
E

Emmanuel Delahaye

newby2c wrote on 10/08/04 :
That's it! It worked! I added the two newline (\n\n) characters to the
*front*, before the long integer (as seen above). I ran the program. Typed
in "this is a test" (without quotes). Hit <ctrl-z>. The number 14 appears,
and the prog. terminates. Excellent!! I don't know *why* it works, but it
does. Anyway, this is a good one for the books.

Thanks R...!!! Thank you all for your input. Now if someone could explain
why this needs to be done this way, I would have gained a very valuable
lesson.

I can't explain this. All I have seen is that yes, there is a problem
with Dev-C++ (4.9.8.7), but it works properly with Borland C 3.1.
 
N

newby2c

Emmanuel Delahaye said:
I can't explain this. All I have seen is that yes, there is a problem
with Dev-C++ (4.9.8.7), but it works properly with Borland C 3.1.

Oh, so it's a compiler thing? Thanks. Do the Dev's there know about this
particular problem?

newby2c
 
K

Keith Thompson

newby2c said:
Oh, so it's a compiler thing? Thanks. Do the Dev's there know about this
particular problem?

More likely it's a runtime library thing, but the library is probably
bundled with the compiler. In any case, it's not really a question
for comp.lang.c; perhaps one of the Windows or MS-DOS programming
groups can help.
 
P

pete

newby2c said:
Thanks. I tried that.

Your written account indicates that you tried something else.
Here is what happens:

I run the program.
I type in some words and use spaces and tabs.
I hit enter key.
Caret starts at new line.
I then hit ctrl-z.
Nothing happens!
I hit ctrl-z again

That's not what I said to do.
Try hitting the enter key a second time, after ctrl-z,
instead of hitting ctrl-z a second time.
 
N

newby2c

pete said:
That's not what I said to do.
Try hitting the enter key a second time, after ctrl-z,
instead of hitting ctrl-z a second time.

I had already tried that method and wrote back to the thread that I never
get the chance to hit the <enter> key a second time (after <ctrl-z>). The
program terminates. Anyway, the problem has been detected (Run-Time Library
problem using Dev-C++ compiler, I think). In case you hadn't followed the
full thread, I have to add two newline characters at the beginning of the
printf statement:

printf("\n\n%ld",nc);

For some reason this actually works. Although at the moment I have no idea
why.

newby2c
 
C

CBFalconer

newby2c said:
That's it! It worked! I added the two newline (\n\n) characters
to the *front*, before the long integer (as seen above). I ran
the program. Typed in "this is a test" (without quotes). Hit
<ctrl-z>. The number 14 appears, and the prog. terminates.
Excellent!! I don't know *why* it works, but it does. Anyway,
this is a good one for the books.

Thanks R...!!! Thank you all for your input. Now if someone
could explain why this needs to be done this way, I would have
gained a very valuable lesson.

It shouldn't make a difference. There is something wrong with
your system. What is it, complete with what compiler, etc. you
are using.
 
R

RoSsIaCrIiLoIA

newby2c wrote on 10/08/04 :

I can't explain this. All I have seen is that yes, there is a problem
with Dev-C++ (4.9.8.7), but it works properly with Borland C 3.1.

not with windows-95 + borland C 3.0 (it needs a '\n')
I think it is getchar() that want a '\n' for terminate the input in
console (after EOF==<ctrl-z>) elsewhere *the first line in output*
after that is eaten.
 
N

newby2c

CBFalconer said:
It shouldn't make a difference. There is something wrong with
your system. What is it, complete with what compiler, etc. you
are using.

I'm using win98(*not* se).
I'm using Dev-C++ (version 4.9.9.0) as my compiler.
And as mentioned before, I *do* use the command line at a DOS console rather
than running the program from the IDE.

Thanks,
newby2c
 
C

CBFalconer

newby2c said:
I'm using win98(*not* se).
I'm using Dev-C++ (version 4.9.9.0) as my compiler.
And as mentioned before, I *do* use the command line at a DOS
console rather than running the program from the IDE.

Go to www.delorie.com, use the zip-picker to get enough to compile
and run C programs, and download their installation of gcc. Try
the same sources. That will probably demonstrate that dev-c++ is
wrong. I believe that is also based on gcc.
 
K

Kenneth Brody

newby2c said:
Thanks again.
Ran prog. Typed line. Hit <enter> (the caret moved to new line).
Hit <ctrl-z>. Prog. terminates.
Never had a chance to hit <enter>.
This was the program in it's original form (without getchar();).
With the getchar(); in place just before the return 0; I type some words,
hit <enter>, then hit <ctrl-z>, (prog. does *not* terminate), lastly I hit
<enter>. The prog. terminates, but there is still no output.

newby2c

newby2c

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.
 
N

newby2c

CBFalconer said:
Go to www.delorie.com, use the zip-picker to get enough to compile
and run C programs, and download their installation of gcc. Try
the same sources. That will probably demonstrate that dev-c++ is
wrong. I believe that is also based on gcc.

Thanks CB, I just may try that.

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,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top