473,509 Members | 6,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ascii value of EOF

3 New Member
its well known that EOF has value -1.
but does it have any ASCII value???
Aug 25 '10 #1
6 18971
utkarshjadhav
3 New Member
And other question (very basic and funny one)--
when we finish writing a file...How and when EOF gets associated with it..??
if EOF is only -1 (and nothing else)
What will happen while reading another -1 (which is within the file)?
Aug 25 '10 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
Who said EOF is -1?

If EOF is -1 then the code should use -1 and avoid all the mystery. But EOF is not guaranteed to be -1. It may be anything so you use EOF in your code.

The -1 is an assumption. Like the guy who thinks FALSE is 0 (except in Visual Basic where it's -1). Avoid assumptions.
Aug 25 '10 #3
utkarshjadhav
3 New Member
@ weaknessforcats:
But for the following program in DevC++,in the file demo.c--
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. int main()
  3. {
  4.         int c=EOF;
  5.         printf("%d",c);
  6.         getch();
  7.         return(0); 
  8.  
  9. }
  10.  
It showed -1...
Aug 25 '10 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
Maybe I wasn't clear.

EOF has to be a number larger than the largest number of bytes that you can put in a file. Otherwise, it can't be EOF.

In your compiler's case -1 was picked because no file can have -1 bytes in it. Therefore, the value of EOF can't be confused with any valid position in the file.

But -2 would also work. As would -222 or -123434566. The fact that your compiler uses -1 is only interesting. But your code better use EOF or it may not work when compiled on someone else's compiler.
Aug 25 '10 #5
johny10151981
1,059 Top Contributor
in visual studio EOF is defined like below:
Expand|Select|Wrap|Line Numbers
  1. #define EOF (-1)
Same in Linux (checked on CentOS)
Aug 25 '10 #6
Oralloy
988 Recognized Expert Contributor
There is a "ASCII" EOF indicator.

It's called FS - file separator, value 0x1C.

There is also EOT - end of transmission, value 0x04, entered as ctrl-D under the Unix/Linux command line.

And, of course, PC-DOS/Windoze uses SUB - substitute, value 0x1a, entered as ctrl-Z, as it's command line end of file character.

So, pick one.....

The problem is that all of these are representable as ASCII codes which may quite reasonably appear in a binary data stream.

That's why the special token, EOF, is used in source code. The value of -1 is just handy and obvious.

Also, since ASCII is a seven bit code, it's still a useful value when used in 8-bit byte encoding. Probably not something that concerns you, though.

Did you observe that functions like getc() return integers? This keeps the -1 EOF value from conflicting with the 8 bit value 0xff, which may be valid in the data stream.

Does that help?
Aug 25 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
6169
by: Steve Horsley | last post by:
How can I get the ASCII value of a character, e.g. I have: str = "A B" for index in range(0, len(str)): value = WHAT_GOES_HERE?(str) print value and I hope to get: 65
6
8691
by: Haas | last post by:
Hello folks, I just started a C++ course. An exercise is to give the ASCII value of a character read from keyboard. I place the input from the keyboard in a char-variable. How can i get the...
1
2571
by: James Dean | last post by:
i want to be able to get the correct ascii value from a byte without having to use the Convert.ToChar function as a char takes up two bytes of space and it is affecting the performance of my...
1
10550
by: RAGHAVENDRAS | last post by:
Hi All, I am writing a script for getting the ASCII value for the keyboard input. The script: #!c:\perl\bin -w # sascii - Show ASCII values for keypresses use Term::ReadKey;...
0
3379
by: JohnLongHorn97 | last post by:
Hello everyone, I would like to write a script that will read several ascii characters directly into the STDIN, so it will be like I pressed these values in my keyboard, in another window. for...
2
1650
saranjegan
by: saranjegan | last post by:
Dudes, this is my doubt i need to rename a file,i can make it thru rename function..but the modified name should be an original name added with ascii value of 23.. these are questions...
1
10598
by: sajit | last post by:
hi folks, I am developing a module in asp.net with c# as code behind. The module is used to encrypte the password. The problem is how to find the ascii value of particular character. Any help...
1
9284
by: ssetz | last post by:
Hello, For work, I need to write a password filter. The problem is that my C+ + experience is only some practice in school, 10 years ago. I now develop in C# which is completely different to me....
2
1172
by: hellboss | last post by:
Hi ! im working with asp.net(vb) I need to get the ASCII value for a set of text which is typed in a text box. I use a text box and a button, clicking on the button should show the equivalent ascii...
0
1307
by: shisheel | last post by:
Respected experts i am doing a project on the basis of c, For this I need a guidelines. After converting the ASCII value of the charecter that will be converted to its binary...
0
7237
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
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7416
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
7073
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
5656
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
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1571
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 ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.