473,466 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

About the EOF

Hi everyone! I am a beginner in C. I knew the EOF is -1, but can anyone
tell me how can I type the EOF on the screen using the keyboard?

Jan 21 '06 #1
7 1541
On Sat, 21 Jan 2006 00:28:00 -0800, Kies Lee wrote:
Hi everyone! I am a beginner in C. I knew the EOF is -1, but can anyone
tell me how can I type the EOF on the screen using the keyboard?


Type <Ctrl>+d .
Jan 21 '06 #2

"Kies Lee" <ll****@gmail.com> wrote in message
Hi everyone! I am a beginner in C. I knew the EOF is -1, but can anyone
tell me how can I type the EOF on the screen using the keyboard?

It depends on your sytem.
Try CTRL-Z to generate an EOF from the keyboard in DOS.

You cannot print an EOF chararacter on the screen (normally). If you try,
what will probably happen is that it interprets a -1 as 255, which may be a
printable character or may not be.
To do this

printf("%***%c***\n", EOF);

it's probably technically undefined behaviour, but you will see the result.
Jan 21 '06 #3
Malcolm wrote:

"Kies Lee" <ll****@gmail.com> wrote in message
Hi everyone! I am a beginner in C. I knew the EOF is -1, but
can anyone tell me how can I type the EOF on the screen using
the keyboard?
It depends on your sytem.
Try CTRL-Z to generate an EOF from the keyboard in DOS.


And CTRL-D on Linux/Unix... YMMV

You cannot print an EOF chararacter on the screen (normally).
True, but you can print its value, as it's guaranteed to be an
int. Store your return value into an int variable, and once you
get an EOF print it out as an integer.
If you try, what will probably happen is that it interprets a
-1 as 255, which may be a printable character or may not be.
To do this

printf("%***%c***\n", EOF);

it's probably technically undefined behaviour, but you will
see the result.


It's wrong in the sense that you're trying to print an int using
a char format specifier. If you used %d, you'd get the value of
EOF as defined on your system (it's not necessarily a valid
character).

Cheers

Vladimir

Jan 21 '06 #4
Kies Lee wrote:
Hi everyone! I am a beginner in C. I knew the EOF is -1,
I'm sorry, but you misunderstand. EOF is a macro that expands to a
negative integer, and on many systems that integers is -1, but that is
not guaranteed. Whatever value EOF expands to is the value that various
IO functions return to indicate and end-of-file or error condition.
but can anyone
tell me how can I type the EOF on the screen using the keyboard?


It depends on your system and is thus not topical here. It could be
control+Z, control+D or anything else.

You should have read the comp.lang.c FAQ before posting, in which case
you would have found http://c-faq.com/stdio/eofval.html
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Jan 21 '06 #5
Kies Lee a écrit :
Hi everyone! I am a beginner in C. I knew the EOF is -1,
It's not. The standard says that EOF is a negative int. That said, it is
possible that your implementation choose the value of -1, as recommended
by POSIX (which is not part of the C-language, but a strong standard
either).
but can anyone
tell me how can I type the EOF on the screen using the keyboard?


Badly worded, but you probably want to know how to trig an end of
reading when reading from the keyboard. It's a system issue:

MS-DOS/Windows : crtl-z<enter>
Unixoid : ctrl-d

etc.

--
A+

Emmanuel Delahaye
Jan 21 '06 #6
Kies Lee wrote:
Hi everyone! I am a beginner in C. I knew the EOF is -1,
No, you know no such thing. EOF is a macro which expands to an integer
constant expression, with type int and a negative value. There is no
reason to suppose that that negative value is -1.
but can anyone
tell me how can I type the EOF on the screen using the keyboard?


You need to check the FAQ before posting questions. The question you
need to check in particular is found at
<http://c-faq.com/stdio/eofval.html>, "I have a simple little program
that reads characters until EOF, but how do I actually enter that
``EOF'' value from the keyboard? I see that EOF is defined by <stdio.h>
to be -1; am I supposed to enter -1?". Notice the similarity to your
question?

Jan 21 '06 #7
"Kies Lee" <ll****@gmail.com> writes:
Hi everyone! I am a beginner in C. I knew the EOF is -1, but can anyone
tell me how can I type the EOF on the screen using the keyboard?


No EOF isn't necessarily -1; the standard merely says that it's a
negative value. (Most, possibly all, implementations use -1, but you
shouldn't depend on it.)

Keep in mind that end-of-file is a condition, not a character; the
value EOF is used to indicate that you've reached the end of the file.

How you cause and end-of-file condition varies from one system to
another. On Unix-like systems control-D is most common (once at the
beginning of a line, twice in the middle of a line). On DOS and
Windows systems, control-Z is most common.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 21 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
8
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew...
77
by: nospam | last post by:
Reasons for a 3-tier achitecture for the WEB? (NOTE: I said, WEB, NOT WINDOWS. DON'T shoot your mouth off if you don't understand the difference.) I hear only one reason and that's to switch a...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
5
by: eScrewDotCom | last post by:
www.eScrew.com eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is...
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
0
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew...
7
by: Edward Yang | last post by:
A few days ago I started a thread "I think C# is forcing us to write more (redundant) code" and got many replies (more than what I had expected). But after reading all the replies I think my...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.