Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > info about EOF

Reply
Thread Tools

info about EOF

 
 
alok
Guest
Posts: n/a
 
      03-21-2011
if(getchar() != EOF)

what is the value of EOF and for what keyborad input the if statement
will fail?
 
Reply With Quote
 
 
 
 
Seebs
Guest
Posts: n/a
 
      03-21-2011
On 2011-03-21, alok <> wrote:
> if(getchar() != EOF)
>
> what is the value of EOF and for what keyborad input the if statement
> will fail?


This question seems awfully homeworky.

So, help us out here. What have you already tried to do in order to
figure out the answer to this question? What are you stuck on?

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
 
 
 
Morris Keesan
Guest
Posts: n/a
 
      03-21-2011
On Mon, 21 Mar 2011 14:19:58 -0400, alok <> wrote:

> if(getchar() != EOF)
>
> what is the value of EOF and for what keyborad input the if statement
> will fail?


The value of EOF is EOF, which is a negative value of type (int), which
cannot be represented in an (unsigned char). The exact value is up to
the implementation, and you should try not to know what it is, because
if you know the value you're liable to write code which expects that value,
and that code will fail when you try to run it on a different platform.

What keyboard input generates an EOF is system-dependent, and on the
systems I most often write C code for, the EOF character can be changed
by the user.
--
Morris Keesan --
 
Reply With Quote
 
Malcolm McLean
Guest
Posts: n/a
 
      03-22-2011
On Mar 22, 1:03*pm, pete <pfil...@mindspring.com> wrote:
> Morris Keesan wrote:
> > What keyboard input generates an EOF is system-dependent,
> > and on the systems I most often write C code for,
> > the EOF character can be changed by the user.

>
> What's an "EOF character" ?
>

In some systems, notably MS-DOS, end of file was indicated by a
special character, control-Z.

Since in C control-Z has to be treated as a valid char, fgetc() and
related functions had to intercept control-Z and translate to an EOF.
EOF is always negative.

 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      03-22-2011
In article <op.vsplubdm5qv6o3@toshiba-laptop>,
Morris Keesan <> wrote:
>On Mon, 21 Mar 2011 14:19:58 -0400, alok <> wrote:
>
>> if(getchar() != EOF)
>>
>> what is the value of EOF and for what keyborad input the if statement
>> will fail?

>
>The value of EOF is EOF, which is a negative value of type (int), which
>cannot be represented in an (unsigned char). The exact value is up to
>the implementation, and you should try not to know what it is, because
>if you know the value you're liable to write code which expects that value,
>and that code will fail when you try to run it on a different platform.


Be wary anytime anyone tells you that you shouldn't know something. This is
very much the stance of the medieval Church.

If you want to know what EOF is on your system, try this:

$ printf '#include <stdio.h>\nmain() {printf("EOF = %%d\\n",EOF);return 0;}'|gcc -xc - && ./a.out && rm ./a.out

which displays EOF = -1 on my system.

--
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...

 
Reply With Quote
 
Mark Bluemel
Guest
Posts: n/a
 
      03-22-2011
On 03/22/2011 11:03 AM, pete wrote:
> Morris Keesan wrote:
>
>> What keyboard input generates an EOF is system-dependent,
>> and on the systems I most often write C code for,
>> the EOF character can be changed by the user.

>
> What's an "EOF character" ?
>

I took it as being shorthand for
"the keystroke (combination) which when entered on a keyboard
(or similar input device) indicates to the operating system
that end of file has been reached. This will be represented
by the C support libraries by delivering the EOF value as the
result of a read from this device."
 
Reply With Quote
 
Mark Bluemel
Guest
Posts: n/a
 
      03-22-2011
On 03/22/2011 12:37 PM, Kenny McCormack wrote:
> In article<op.vsplubdm5qv6o3@toshiba-laptop>,
> Morris Keesan<> wrote:
>> On Mon, 21 Mar 2011 14:19:58 -0400, alok<> wrote:
>>
>>> if(getchar() != EOF)
>>>
>>> what is the value of EOF and for what keyborad input the if statement
>>> will fail?

>>
>> The value of EOF is EOF, which is a negative value of type (int), which
>> cannot be represented in an (unsigned char). The exact value is up to
>> the implementation, and you should try not to know what it is, because
>> if you know the value you're liable to write code which expects that value,
>> and that code will fail when you try to run it on a different platform.

>
> Be wary anytime anyone tells you that you shouldn't know something. This is
> very much the stance of the medieval Church.


That isn't what Morris said and he explained the risks associated with
assuming a value for EOF.
 
Reply With Quote
 
Mark Bluemel
Guest
Posts: n/a
 
      03-22-2011
On 03/21/2011 06:19 PM, alok wrote:
> if(getchar() != EOF)
>
> what is the value of EOF


The language specification says
" EOF
.... expands to an integer constant expression, with type int and a
negative value, that is returned by several functions to indicate
end-of-file, that is, no more input from a stream"

Note that the precise value is not specified - it is frequently -1
but this is not required.

> and for what keyborad input the if statement
> will fail?


This is not a question about the language, but about the platform.
Different platforms have different ways of representing end-of-input
on a keyboard. Common examples are ctrl-z (windows) and ctrl-d (default
for at least some Unix/Linux shells). These values can be changed in
some environments (for example with the stty command on Unix/Linux).

Try reading Section 12 of the C FAQ at http://c-faq.com - you've more
or less asked questions 12.1 and 12.1b
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      03-22-2011
In article <ima7eu$j21$>,
Mark Bluemel <> wrote:
>On 03/22/2011 12:37 PM, Kenny McCormack wrote:
>> In article<op.vsplubdm5qv6o3@toshiba-laptop>,
>> Morris Keesan<> wrote:
>>> On Mon, 21 Mar 2011 14:19:58 -0400, alok<> wrote:
>>>
>>>> if(getchar() != EOF)
>>>>
>>>> what is the value of EOF and for what keyborad input the if statement
>>>> will fail?
>>>
>>> The value of EOF is EOF, which is a negative value of type (int), which
>>> cannot be represented in an (unsigned char). The exact value is up to
>>> the implementation, and you should try not to know what it is, because
>>> if you know the value you're liable to write code which expects that value,
>>> and that code will fail when you try to run it on a different platform.

>>
>> Be wary anytime anyone tells you that you shouldn't know something. This is
>> very much the stance of the medieval Church.

>
>That isn't what Morris said ...


I think even the most experienced CLC word parser would be very hard-pressed
to explain how Morris didn't say that you shouldn't know the value of EOF.

--
Just for a change of pace, this sig is *not* an obscure reference to
comp.lang.c...

 
Reply With Quote
 
Malcolm McLean
Guest
Posts: n/a
 
      03-22-2011
On Mar 22, 2:37*pm, gaze...@shell.xmission.com (Kenny McCormack)
wrote:
>
> Be wary anytime anyone tells you that you shouldn't know something. *This is
> very much the stance of the medieval Church.
>

Information hiding is a good ecclesiastical as well as programming
principle.

If you give people information they don't need they might misuse it,
bringing down the entire system.



 
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
Clear the Render info & change to different info Andrea Williams ASP .Net 2 10-27-2004 10:01 PM
How to get the Operating System info like ( Wireless info, Wireless connection) Vasanth Perl 0 06-28-2004 08:56 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57