[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

info about EOF

alok

3/21/2011 6:20:00 PM

if(getchar() != EOF)

what is the value of EOF and for what keyborad input the if statement
will fail?
65 Answers

Seebs

3/21/2011 7:56:00 PM

0

On 2011-03-21, alok <manglikalok@gmail.com> 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-nospam@seebs.net
http://www.seeb... <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/...(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

Morris Keesan

3/21/2011 8:00:00 PM

0

On Mon, 21 Mar 2011 14:19:58 -0400, alok <manglikalok@gmail.com> 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 -- mkeesan@post.harvard.edu

Malcolm McLean

3/22/2011 11:00:00 AM

0

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.

pete

3/22/2011 11:04:00 AM

0

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

--
pete

gazelle

3/22/2011 12:38:00 PM

0

In article <op.vsplubdm5qv6o3@toshiba-laptop>,
Morris Keesan <mkeesan@post.harvard.edu> wrote:
>On Mon, 21 Mar 2011 14:19:58 -0400, alok <manglikalok@gmail.com> 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...

Mark Bluemel

3/22/2011 1:14:00 PM

0

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

Mark Bluemel

3/22/2011 1:15:00 PM

0

On 03/22/2011 12:37 PM, Kenny McCormack wrote:
> In article<op.vsplubdm5qv6o3@toshiba-laptop>,
> Morris Keesan<mkeesan@post.harvard.edu> wrote:
>> On Mon, 21 Mar 2011 14:19:58 -0400, alok<manglikalok@gmail.com> 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.

Mark Bluemel

3/22/2011 1:28:00 PM

0

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:/... - you've more
or less asked questions 12.1 and 12.1b

gazelle

3/22/2011 1:42:00 PM

0

In article <ima7eu$j21$2@news.eternal-september.org>,
Mark Bluemel <mark_bluemel@pobox.com> wrote:
>On 03/22/2011 12:37 PM, Kenny McCormack wrote:
>> In article<op.vsplubdm5qv6o3@toshiba-laptop>,
>> Morris Keesan<mkeesan@post.harvard.edu> wrote:
>>> On Mon, 21 Mar 2011 14:19:58 -0400, alok<manglikalok@gmail.com> 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...

Malcolm McLean

3/22/2011 2:07:00 PM

0

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.