Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > EOF question

Reply
Thread Tools

EOF question

 
 
newby2c
Guest
Posts: n/a
 
      08-10-2004
"RoSsIaCrIiLoIA" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      08-10-2004
newby2c <(E-Mail Removed)> scribbled the following:
> "Emmanuel Delahaye" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> I think you must hit <ctrl-z> <enter>


> 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, he meant first hit <ctrl-z> and then hit <enter>.

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"To err is human. To really louse things up takes a computer."
- Anon
 
Reply With Quote
 
 
 
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      08-10-2004
newby2c wrote on 10/08/04 :
> "Emmanuel Delahaye" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> I think you must hit <ctrl-z> <enter>

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

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

"C is a sharp tool"

 
Reply With Quote
 
RoSsIaCrIiLoIA
Guest
Posts: n/a
 
      08-10-2004
On Tue, 10 Aug 2004 10:55:25 -0400, "newby2c" wrote:
>"RoSsIaCrIiLoIA" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed).. .
>> 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
>

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;
}


 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      08-10-2004
newby2c wrote:
> "CBFalconer" <(E-Mail Removed)> wrote in message
>
>> That sounds like a fault in the system, probably Microsofts. Try
>> ctrl-z return.

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

--
"Churchill and Bush can both be considered wartime leaders, just
as Secretariat and Mr Ed were both horses." - James Rhodes.
"A man who is right every time is not likely to do very much."
- Francis Crick, co-discover of DNA


 
Reply With Quote
 
newby2c
Guest
Posts: n/a
 
      08-10-2004
"CBFalconer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
newby2c
Guest
Posts: n/a
 
      08-10-2004
"Joona I Palaste" <(E-Mail Removed)> wrote in message
news:cfaqo1$anq$(E-Mail Removed)...
> 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


 
Reply With Quote
 
newby2c
Guest
Posts: n/a
 
      08-10-2004
"Emmanuel Delahaye" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> No. Hit them in sequence.
> <ctrl-z>
> then
> <enter>


Hi Emmanuel,

I had already tried that to no avail.

newby2c


 
Reply With Quote
 
newby2c
Guest
Posts: n/a
 
      08-10-2004
"RoSsIaCrIiLoIA" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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


 
Reply With Quote
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      08-10-2004
newby2c wrote on 10/08/04 :
>> #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.


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.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

"C is a sharp tool"

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Windows] Any way to distinguish ^C Induced EOF from ^Z EOF? Jan Burse Java 67 03-14-2012 12:21 AM
ifstream eof not reporting eof? SpreadTooThin C++ 10 06-15-2007 08:49 AM
if EOF = -1, can't a valid character == EOF and cause problems? Kobu C Programming 10 03-04-2005 10:40 PM
A question about EOF SL_McManus Perl 1 12-04-2003 01:50 AM
Newbie Question: EOF in MS Visual Studio 2003? entropy123 C Programming 6 07-03-2003 06:25 PM



Advertisments