I have a problem in my study

M

Mark McIntyre

EOF is an int.

Lets be completely rigorous, so as to avoid any further confusion
between EOF and EOF :)

EOF is macro returned by some library functions when an EOF condition
is signalled by the IO library. The EOF macro is in integer constant
with type int and a negative value. The EOF signal is something that
you need to generate if you want the OP's original proggy to work.
Neither of the above is necessarily the same as the EOF character
found in some ASCII charsets.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
K

Keith Thompson

Mark McIntyre said:
Lets be completely rigorous, so as to avoid any further confusion
between EOF and EOF :)

Yes, let's be completely rigorous.
EOF is macro returned by some library functions when an EOF condition
is signalled by the IO library. The EOF macro is in integer constant
with type int and a negative value. The EOF signal is something that
you need to generate if you want the OP's original proggy to work.
Neither of the above is necessarily the same as the EOF character
found in some ASCII charsets.

EOF is a macro defined in <stdio.h>. It "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 it's an integer constant
*expression*; an integer constant cannot have a negative value.

There is no "EOF signal". There is an end-of-file *indicator*
associated with an input stream. The word "signal" means something
else; see C99 7.14, "Signal handling", for details. I understand that
you were using the term "signal" in its common English sense, but it's
important to be precise.

<OT>
There is no character in ASCII named "EOF". Perhaps you're thinking
of "EOT"? Or was there an "EOF" character in some obsolete version of
ASCII?
</OT>

If you're running a program that takes input from an interactive
device (say, a keyboard), you need to know how to cause the
end-of-file indicator for an input stream associated with that device
to be set. That, I believe, is the probelm the OP was having (Mark,
you were right about that). The C standard says nothing about how
this is done, but typically typing either control-D or control-Z,
depending on the system, will do the job. This causes the end-of-file
indicator to be set, which causes the next call to getchar() (or
fgetc(), or ...) to return the value of EOF. (It also causes a call
to feof() to return true, but that's not as useful as some programmers
think it is.)
 
M

Mark McIntyre

Yes, let's be completely rigorous.


EOF is a macro defined in <stdio.h>.

I said that, I can't see any reason for you to repeat it, especially
since all you did was requote the part of the standard I quoted, but
there you go.
There is no "EOF signal".

I disagree entirely. What do /you/ think your hardware does when you
press the magic keys that "create" an end-of-file event, if not signal
it?
The word "signal" means something else;


This is the sort of thing that gets people a name for excessive
anality.
see C99 7.14, "Signal handling", for details. I understand that
you were using the term "signal" in its common English sense,

Then why did you bother to be so silly?
<OT>
There is no character in ASCII named "EOF".

If you actually read what I said, you'll see that I never said that
there was.
Perhaps you're thinking
of "EOT"? Or was there an "EOF" character in some obsolete version of
ASCII?

I have one in the printed manuals for my PCXT, at position decimal 26.
Which makes sense when you consider how you signalled EOF on such
hardware.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
K

Keith Thompson

Mark McIntyre said:
I said that, I can't see any reason for you to repeat it, especially
since all you did was requote the part of the standard I quoted, but
there you go.

Yes, EOF is a macro; that part of your paragraph was correct. The
rest of your paragraph was, in my opinion, imprecise, especially given
that it was preceded by "Lets be completely rigorous".
I disagree entirely. What do /you/ think your hardware does when you
press the magic keys that "create" an end-of-file event, if not signal
it?

I have no idea what my hardware does. The fact is, the word "signal"
has a specific meaning in C, and it doesn't apply here.

[snip]
If you actually read what I said, you'll see that I never said that
there was.

What you said was:
| Neither of the above is necessarily the same as the EOF character
| found in some ASCII charsets.

ASCII is a standard; it doesn't include a character named "EOF". I
suppose some character sets based on the ASCII standard might include
something called "EOF". I thought it was worth making the distinction
since we're being "completely rigorous". (And I may have slightly
misunderstood what you meant.)
I have one in the printed manuals for my PCXT, at position decimal 26.
Which makes sense when you consider how you signalled EOF on such
hardware.

Ok, but ASCII refers to that character as SUB.
 
M

Mark McIntyre

^^^^
Yes, EOF is a macro; that part of your paragraph was correct. The
rest of your paragraph was, in my opinion, imprecise, especially given
that it was preceded by "Lets be completely rigorous".

Obviously you missed the smiley

(rest of thread snipped, as we both know we're being foolishly anal)
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 

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

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,248
Latest member
MagdalenaB

Latest Threads

Top