Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Newbie Question: EOF in MS Visual Studio 2003?

Reply
Thread Tools

Newbie Question: EOF in MS Visual Studio 2003?

 
 
entropy123
Guest
Posts: n/a
 
      07-02-2003
Hey all,

A newbie, I am working through Kernighan and Ritchie.

I'm having a problem with one of their test programs & MS VS 2003. In
particular the EOF value for VS2003 in winxp is apparently '-1'
However when I enter '-1' as a character in this program the program
(which ought to terminate when EOF is input) will not quit. I need to
hit 'ctrl-c' to exit the program ----> no output...

Thanks for your help,
entropy

Here is the program:

#include <stdio.h>

int main()
{
int c, nl;

nl = 0;
while (( c = getchar() ) != EOF)
if ( c == '\n')
++nl;
printf("%d\n", nl);
}
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      07-02-2003
entropy123 <(E-Mail Removed)> scribbled the following:
> Hey all,


> A newbie, I am working through Kernighan and Ritchie.


> I'm having a problem with one of their test programs & MS VS 2003. In
> particular the EOF value for VS2003 in winxp is apparently '-1'
> However when I enter '-1' as a character in this program the program
> (which ought to terminate when EOF is input) will not quit. I need to
> hit 'ctrl-c' to exit the program ----> no output...


> Thanks for your help,
> entropy


You have misunderstood what EOF is. It is *not* a character. It does
not exist in the stream at all. It is an extra-special return code from
getchar(). It means "due to some implementation-specific magic, the
stream closed up. I'll pull this -1 thingy out of my hat to make up for
it." Really. That's all it means.
If you want to tell the program yourself that there will be no more
data, you have to use some implementation-specific magic yourself. On
Windows, this involves typing ctrl-Z. On Unix, it is ctrl-D. On Amiga,
it is ctrl-\. I don't know about other platforms.

> Here is the program:


> #include <stdio.h>


> int main()
> {
> int c, nl;


> nl = 0;
> while (( c = getchar() ) != EOF)
> if ( c == '\n')
> ++nl;
> printf("%d\n", nl);
> }


--
/-- Joona Palaste ((E-Mail Removed)) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Immanuel Kant but Genghis Khan."
- The Official Graffitist's Handbook
 
Reply With Quote
 
 
 
 
Lew Pitcher
Guest
Posts: n/a
 
      07-02-2003
Joona I Palaste wrote:
> entropy123 <(E-Mail Removed)> scribbled the following:
>
>>Hey all,

>
>
>>A newbie, I am working through Kernighan and Ritchie.

>
>
>>I'm having a problem with one of their test programs & MS VS 2003. In
>>particular the EOF value for VS2003 in winxp is apparently '-1'
>>However when I enter '-1' as a character in this program the program
>>(which ought to terminate when EOF is input) will not quit. I need to
>>hit 'ctrl-c' to exit the program ----> no output...

>
>
>>Thanks for your help,
>>entropy

>
>
> You have misunderstood what EOF is. It is *not* a character. It does
> not exist in the stream at all. It is an extra-special return code from
> getchar(). It means "due to some implementation-specific magic, the
> stream closed up. I'll pull this -1 thingy out of my hat to make up for
> it." Really. That's all it means.
> If you want to tell the program yourself that there will be no more
> data, you have to use some implementation-specific magic yourself. On
> Windows, this involves typing ctrl-Z. On Unix, it is ctrl-D.


Or not

/If/ the stream is redirected from a file, then the physical act of
attempting to read beyond the last byte of data invokes the passing of EOF.

OTOH, if the stream is read from a 'character special device' (i.e., a
terminal or similar), the OS interprets (or not) the characters, and
delivers the metadata signal of "reading beyond the last byte of data" based
on the character read. Since this character is configurable, it /can/ be
ctrl-D, but doesn't /have to be/ ^D. Indeed, if the device is conditioned to
be deliver data in 'raw' mode (admittedly, a condition and operation that's
off-topic in CLC), the system may /never/ signal that an end-of-data
condition has been encountered.


> On Amiga,
> it is ctrl-\. I don't know about other platforms.

[snip]


--

Lew Pitcher, IT Consultant, Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)

 
Reply With Quote
 
entropy123
Guest
Posts: n/a
 
      07-02-2003
>
> You have misunderstood what EOF is. It is *not* a character. It does
> not exist in the stream at all. It is an extra-special return code from
> getchar(). It means "due to some implementation-specific magic, the
> stream closed up. I'll pull this -1 thingy out of my hat to make up for
> it." Really. That's all it means.
> If you want to tell the program yourself that there will be no more
> data, you have to use some implementation-specific magic yourself. On
> Windows, this involves typing ctrl-Z. On Unix, it is ctrl-D. On Amiga,
> it is ctrl-\. I don't know about other platforms.
>

Joona,

Thanks for your help. It certainly is ctrl-z. I can understand why a
book last revised in 1989 might not have the info...but not in the VS
2003 help files....

entropy
>
> > Here is the program:

>
> > #include <stdio.h>

>
> > int main()
> > {
> > int c, nl;

>
> > nl = 0;
> > while (( c = getchar() ) != EOF)
> > if ( c == '\n')
> > ++nl;
> > printf("%d\n", nl);
> > }

 
Reply With Quote
 
istartedi
Guest
Posts: n/a
 
      07-03-2003

entropy123 <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> >
> > You have misunderstood what EOF is. It is *not* a character. It does
> > not exist in the stream at all. It is an extra-special return code from
> > getchar(). It means "due to some implementation-specific magic, the
> > stream closed up. I'll pull this -1 thingy out of my hat to make up for
> > it." Really. That's all it means.
> > If you want to tell the program yourself that there will be no more
> > data, you have to use some implementation-specific magic yourself. On
> > Windows, this involves typing ctrl-Z. On Unix, it is ctrl-D. On Amiga,
> > it is ctrl-\. I don't know about other platforms.
> >

> Joona,
>
> Thanks for your help. It certainly is ctrl-z. I can understand why a
> book last revised in 1989 might not have the info...but not in the VS
> 2003 help files....


I think they were assuming that the target audience was familiar with the
DOS command-line. I'm not trying to insult you, but I think you need to
learn more about the command-line. Google for some tutorials. It feels
funny for me to say this, but I have to say don't waste your time learning
too much about the DOS/Windows CLI. The *NIX shells seem to be where the
future is at as far as CLIs are concerned, and you can run them on Windows
(easiest way is via Cygwin) if you want to practice without partitioning
your hard drive.

Raise your hand if you think "knows all the ins and outs of the DOS/Windows
CLI tools and batch file programming" is going to sound a lot like "COBOL
programmer" in a few years. Actually, it already does to me.

--$teve



 
Reply With Quote
 
Arthur J. O'Dwyer
Guest
Posts: n/a
 
      07-03-2003

On Thu, 3 Jul 2003, istartedi wrote:
>
> Raise your hand if you think "knows all the ins and outs of the DOS/Windows
> CLI tools and batch file programming" is going to sound a lot like "COBOL
> programmer" in a few years. Actually, it already does to me.


Batch-file programming is definitely old-skool in my mind, but I have to
say that my life at the moment would be a lot more tedious *without* batch
files. DOS command-line tools: well, I *was* going to say that I use
them all the time, until I realized that most of what I use regularly is
really the DJGPP textutils set, and not DOS at all - cat, less, diff,...
I hardly ever use type, more, or fc anymore. And I assume you're not
going to count del, deltree, dir, copy, mkdir, move, or ren. For a speedy
typer, they're a heck of a lot simpler than the Windows file system
interface.

-Arthur
 
Reply With Quote
 
entropy123
Guest
Posts: n/a
 
      07-03-2003
>
> I think they were assuming that the target audience was familiar with the
> DOS command-line. I'm not trying to insult you, but I think you need to
> learn more about the command-line. Google for some tutorials. It feels
> funny for me to say this, but I have to say don't waste your time learning
> too much about the DOS/Windows CLI. The *NIX shells seem to be where the
> future is at as far as CLIs are concerned, and you can run them on Windows
> (easiest way is via Cygwin) if you want to practice without partitioning
> your hard drive.
>
> Raise your hand if you think "knows all the ins and outs of the DOS/Windows
> CLI tools and batch file programming" is going to sound a lot like "COBOL
> programmer" in a few years. Actually, it already does to me.
>
> --$teve


$teve,

No, not insulted at all. I'm famiiar with *NIX shells and their
command lines, but just had no clue in winxp. One of my many
misconceptions had to do with "winxp EOF" searches that yielded little
or poor results...

I agree I need to look into explicit DOS command line commands....at
least for the time being...

entropy
 
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
Is Visual Studio 2005 complict with Visual Studio 2003 rockdale ASP .Net 1 08-23-2006 07:20 PM
Should I write Visual studio 2005 or Visual studio 2003 MCSD =?Utf-8?B?VmlqYXk=?= Microsoft Certification 14 06-30-2006 09:05 AM
Is Visual Studio Team System and Visual Studio Foundation Server are same?. Thirumalai ASP .Net 0 05-22-2006 08:48 AM
visual studio .net 2003 verses visual studio .net 2002 wh ASP .Net 2 01-16-2004 04:54 PM



Advertisments