Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > EOF (novice)

Reply
Thread Tools

EOF (novice)

 
 
Ed Morton
Guest
Posts: n/a
 
      11-19-2003


On 11/18/2003 8:02 PM, Alan Connor wrote:
> On Wed, 19 Nov 2003 01:30:57 -0000, Seesaw <(E-Mail Removed)> wrote:
>
>>
>>When you enter -1, you enter two characters '-' and '1'. Neither equals -1.
>>Maybe you should enter Ctrl-D(?), which will produce a EOF.

>
>
> Ctrl-c works just fine.


Typing Ctrl-D is usually, but not always, how to provide an EOF. Typing that
when manually entering input is just like if you ran your program redirecting
input from a text file instead of typing it you'd get an EOF at the end of the
input stream. Typing Ctrl-C (or "Ctrl-?" or "Del" or whatever your interrupt
keystroke happens to be) interrupts the running process just like it would if
that process were exeucting a shell script instead of a C program.

But absolutely nothing was said about this
> in K&R or the FAQ.


Well, no, it wouldn't be. It isn't a C issue, it's a UNIX one, and it's a
question that I've never seen asked before in this NG so it wouldn't qualify as
"Frequently Asked". It is, however, addressed in the ksh manual page:

eof End-of-file character, normally ^D, is processed
as an End-of-file.....

Regards,

Ed.


 
Reply With Quote
 
 
 
 
Kevin Bracey
Guest
Posts: n/a
 
      11-19-2003
In message <QMDub.6596$(E-Mail Removed). net>
"Mike Wahler" <(E-Mail Removed)> wrote:

> "Alan Connor" <(E-Mail Removed)> wrote in message
> news:KfDub.5447$(E-Mail Removed) ink.net...
> > On Tue, 18 Nov 2003 22:39:09 -0600, Morris Dovey <(E-Mail Removed)> wrote:
> >
> > > K&R attempts (and succeeds) in providing a /succinct/
> > > presentation of the language. Messrs Kernighan and Ritchie
> > > /don't/ spoon feed the reader; they expect us to read with our
> > > brains fully engaged.

> >
> > That's a strange way to put it: "spoon feed".
> >
> > It is a book written for people who already know how to
> > program and want to learn C.
> >
> > No amount of "brain engaging" could EVER have arrived at
> > the use of Ctrl-c or Ctrl-d for that program.

>
> Because neither of those 'keystrokes' (or any others)
> are defined by the language. They're defined by the
> host operating system.


Not necessarily. My OS doesn't have a concept of EOF for terminal input
at all. C assumes one for trivial programs like that, so the C library
itself decides to follow the Unix Ctrl-D convention. I'd agree that this
should be in the FAQ - for many non-Unix systems, terminal EOF is a purely
"C" concept.

I'd been using C for over a year on my platform before I found out about
Ctrl-D; I'd hitherto assumed that EOF wasn't possible on stdin.

--
Kevin Bracey, Principal Software Engineer
Tematic Ltd Tel: +44 (0) 1223 503464
182-190 Newmarket Road Fax: +44 (0) 1223 503458
Cambridge, CB5 8HE, United Kingdom WWW: http://www.tematic.com/
 
Reply With Quote
 
 
 
 
John Bode
Guest
Posts: n/a
 
      11-19-2003
Alan Connor <(E-Mail Removed)> wrote in message news:<NVFub.5591$(E-Mail Removed) link.net>...
> On Wed, 19 Nov 2003 01:35:47 -0600, Morris Dovey <(E-Mail Removed)> wrote:
> >

>
> <snip>
>
> >> No amount of "brain engaging" could EVER have arrived at the
> >> use of Ctrl-c or Ctrl-d for that program.

> >
> > True. The keyboard mechanism isn't part of the language. The
> > standard provides a mechanism to recognize the end-of-file
> > condition for a /stream/ without requiring that there even /be/ a
> > keyboard associated with any of those streams.

>
> You are missing my point: The program as written in K&R *doesn't
> work*. Or it seems not to.


It works *just fine*. If you generate an EOF, it will terminate. The
details of how to generate an EOF on a particular system is beyond the
scope of that particular tutorial. Sorry that got past you.

>
> That part of the book is POORLY WRITTEN. Lame.
>


Maybe you'd prefer Herb Schildt? He's an excellent writer, he just
doesn't know C very well.

> >
> > BTW, on one of my systems Ctrl-Z generates EOF; and on another
> > Ctrl-X has the same effect. A number of the machines I've
> > programmed in C have no keyboard at all.

>
> That's bizarre, but why not? The KB is only *standard* input.


Except for systems where it isn't. Think about any number of embedded
controllers, modems, etc. All The World Is NOT An x86 Desktop System.

[snip rest]
 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      11-19-2003
In <(E-Mail Removed)> Kevin Bracey <(E-Mail Removed)> writes:

>In message <QMDub.6596$(E-Mail Removed). net>
> "Mike Wahler" <(E-Mail Removed)> wrote:
>
>> Because neither of those 'keystrokes' (or any others)
>> are defined by the language. They're defined by the
>> host operating system.

>
>Not necessarily. My OS doesn't have a concept of EOF for terminal input
>at all. C assumes one for trivial programs like that, so the C library
>itself decides to follow the Unix Ctrl-D convention. I'd agree that this
>should be in the FAQ - for many non-Unix systems, terminal EOF is a purely
>"C" concept. ^^^^


Are there so many such systems? The concept seems to predate Unix
and C by a large margin and I've used plenty of systems, some of
them having nothing in common with Unix and not providing a C
implementation at all, but all of them had one way or another of
signaling end of file on the standard input (even the punch card
based ones). The only exceptions I can think of are micros using a BASIC
interpreter instead of an operating system.

>I'd been using C for over a year on my platform before I found out about
>Ctrl-D; I'd hitherto assumed that EOF wasn't possible on stdin.


Reading the implementation's documentation can be a rewarding exercise

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      11-19-2003
Kevin Bracey wrote:
>

.... snip ...
>
> Not necessarily. My OS doesn't have a concept of EOF for terminal
> input at all. C assumes one for trivial programs like that, so the
> C library itself decides to follow the Unix Ctrl-D convention. I'd
> agree that this should be in the FAQ - for many non-Unix systems,
> terminal EOF is a purely "C" concept.


I rather doubt that. However, nothing insists that you can
generate such a signal from the keyboard; it may require physical
destruction of something.

>
> I'd been using C for over a year on my platform before I found out
> about Ctrl-D; I'd hitherto assumed that EOF wasn't possible on
> stdin.


Some systems hide the mechanism. On the HP3000 under MPE it
required ":EOF" at the prompt, after which the terminal was
useless until action was taken by the system operator or the whole
system was taken down and reinitialized. Very useful for playing
pranks. It also meant that you used something else to signal "end
of input".

--
Chuck F ((E-Mail Removed)) ((E-Mail Removed))
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


 
Reply With Quote
 
Alan Connor
Guest
Posts: n/a
 
      11-19-2003
On Wed, 19 Nov 2003 05:09:36 -0600, James Hu <(E-Mail Removed)> wrote:

<snip>

Thanks, James.

AC

 
Reply With Quote
 
Alan Connor
Guest
Posts: n/a
 
      11-19-2003
On Wed, 19 Nov 2003 13:04:02 GMT, CBFalconer <(E-Mail Removed)> wrote:

<snip>

Mr. Falconer. This is the third post in a row I have gotten from you that
is abusive in nature.

Stick them where the sun don't shine and get the **** out of my life.

killfiled for 90 days.


AC

 
Reply With Quote
 
Alan Connor
Guest
Posts: n/a
 
      11-19-2003
On Wed, 19 Nov 2003 10:08:01 -0600, Ed Morton <(E-Mail Removed)> wrote:

<snip>

Thanks, Ed. That was helpful.

AC

 
Reply With Quote
 
Alan Connor
Guest
Posts: n/a
 
      11-19-2003
On 19 Nov 2003 09:48:39 -0800, John Bode <(E-Mail Removed)> wrote:

<snip>

Point taken, John. Thank you.

AC

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      11-19-2003
Alan Connor wrote:

> Stick them where the sun don't shine and get the **** out of my life.


Please don't use foul language on this newsgroup.

Thank you.

--
Richard Heathfield : (E-Mail Removed)
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
 
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
How to check for EOF (End of file) when using StreamReader to parse text file Sacha Korell ASP .Net 2 09-06-2003 02:59 PM



Advertisments