473,883 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

EOF (novice)



--
Alan C this post ends with w
q

From K&R:

#include <stdio.h>

main()

/* copy input to output */

{

int c;

c = getchar();
while (c != EOF) {

putchar(c);
c = getchar();

}

}
If I am reading the text correctly, this program should
terminate when I enter -1 (EOF as defined on my system,
Linux).

But it doesn't. Just keeps right on trucking.

What gives?

AC
Nov 13 '05
76 8877
James Hu wrote:
A single character is sufficient but not necessary. My multi-byte EOF
system is hypothetical.


It doesn't matter. Your multi-byte EOF is still not C's EOF, it's just
a byte sequence which it happens to be possible to interpret as the same
value as the C implementation' s EOF constant. If you keep the system
but replace that C implementation with another which #defines EOF as
some other constant, then the system's EOF byte sequence will remain the
same but it will no longer match that new C implementation' s EOF
constant.

In short C's EOF is C's EOF and not the system's EOF, no matter what
tricks you play with the system's EOF. Assuming the system _has_ an
EOF sequence and not a file-size attribute or something.

--
Hallvard
Nov 13 '05 #71
On 2003-12-02, Hallvard B Furuseth <h.**********@u sit.uio> wrote:
James Hu wrote:
A single character is sufficient but not necessary. My multi-byte EOF
system is hypothetical.


It doesn't matter.


Of course not. "We don't know nor should we care" clearly spells that
out. You claimed that EOF was *not* stored on the physical medium. My
point is that it may or may not be, but to the strictly conforming C
program, it doesn't matter.

Regards,

-- James
Nov 13 '05 #72
In <eM************ ********@comcas t.com> James Hu <jx*@despammed. com> writes:
On 2003-12-02, Dan Pop <Da*****@cern.c h> wrote:
In <IM************ ********@comcas t.com> James Hu <jx*@despammed. com> writes:
It is not inconceivable for a system to buffer read a file and scan
the bytes for a sizeof(int) bytes long bit pattern before determining
whether it should return the next char as input or return EOF instead.
Of course, in such a scheme, the system would need to be able to escape
the bit pattern if it wanted to be able to scan the bytes literally.
(We don't know how it is done, nor should we care.)


I'm afraid I don't get it. Any byte combination can be used in a binary
file without meaning anything at all for the implementation. Only the
program reading the file can assign one meaning or another to a certain
combination of bytes. The standard makes it clear that an implementation
is not required to be able to locate the logical end of a binary file
(in which case, all the characters between the logical eof and the
physical eof are null).


If the standard explicitly or implicitly makes a non requirement, then
the implementation is free to satisfy it or not ("we don't know how it
is done"). A strictly conforming C program cannot make any assumptions
about whether the non requirement is present or not ("nor should we
care").

If you want a practical example, consider a stdio interface implemented
over a compressed filesystem.


I still don't get it. Each and every byte combination is still valid
in a binary file, therefore it *cannot* be used as eof marker.
For text files, a single eof character is enough to mark the end of the
text file, even if the physical file is larger (up to the end of the
logical disk block). This is the well known scheme used by CP/M-80.


A single character is sufficient but not necessary. My multi-byte EOF
system is hypothetical.


That's true and irrelevant in the case of text files. My point is that
your scheme simply does not work for binary files. Furthermore, EOF
is a C macro having no connection with whatever mechanism the
implementation uses to detect the end of a file. All we know about it
is that it expands to a negative integer value.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #73
James Hu wrote:
Of course not. "We don't know nor should we care" clearly spells that
out. You claimed that EOF was *not* stored on the physical medium.


No, I claimed that _C's_ EOF is not. At least that was what I meant to
say. Anyway, maybe we just have been saying the same thing in different
ways.

--
Hallvard
Nov 13 '05 #74

On Tue, 2 Dec 2003, Dan Pop wrote:

In <eM************ ********@comcas t.com> James Hu writes:
On 2003-12-02, Dan Pop <Da*****@cern.c h> wrote:
In <IM************ ********@comcas t.com> James Hu writes:

It is not inconceivable for a system to buffer read a file and scan
the bytes for a sizeof(int) bytes long bit pattern before determining
whether it should return the next char as input or return EOF instead.
Of course, in such a scheme, the system would need to be able to escape
the bit pattern if it wanted to be able to scan the bytes literally.
(We don't know how it is done, nor should we care.)
If you want a practical example, consider a stdio interface implemented
over a compressed filesystem.
I still don't get it. Each and every byte combination is still valid
in a binary file, therefore it *cannot* be used as eof marker.


A trivial example would be an MS-DOS-like hybrid system on which the
byte 0xA1 would indicate the end of each file (text or binary). [Not
a typo; I specifically changed it from 0x1A so that EOF could be
#defined to be 0xA1A1 on this hypothetical 16-bit system.]
"But then how does a program represent the literal byte 0xA1 on
the disk?" you ask. Simple -- escape codes. For example, the EOF
code could be 0xA1A1, and the escape code for the literal byte 0xA1
could be 0xA100 (big-endian). This would satisfy all the requirements
of the C standard on file systems (i.e., precious few), while being
technically possible.
Heck, you could even Huffman-encode every single file on the system
to save space, and use some rare codon to indicate EOF. That's getting
closer to what I think James means by "a compressed filesystem."

For text files, a single eof character is enough to mark the end of the
text file, even if the physical file is larger (up to the end of the
logical disk block). This is the well known scheme used by CP/M-80.


A single character is sufficient but not necessary. My multi-byte EOF
system is hypothetical.


That's true and irrelevant in the case of text files. My point is that
your scheme simply does not work for binary files.


[In case Dan hasn't already thought of this: fseek() is not required
to run in constant time. Binary files don't have to be random-access
in their "natural state"; it just happens that all existing systems
do it that way.]
Furthermore, EOF
is a C macro having no connection with whatever mechanism the
implementation uses to detect the end of a file. All we know about it
is that it expands to a negative integer value.


Correct, of course. But I just gave a possible implementation
on which the system's EOF marker, 0xA1A1, is exactly the same value
as the C compiler's EOF value. So James' scenario is not impossible,
merely implausible. Heck, for all I know it might be *common* on
some highly esoteric platforms! ;-)

-Arthur

Nov 13 '05 #75
In <Pi************ *************** ********@unix49 .andrew.cmu.edu > "Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> writes:

On Tue, 2 Dec 2003, Dan Pop wrote:

In <eM************ ********@comcas t.com> James Hu writes:
>On 2003-12-02, Dan Pop <Da*****@cern.c h> wrote:
>> In <IM************ ********@comcas t.com> James Hu writes:
>>
>>>It is not inconceivable for a system to buffer read a file and scan
>>>the bytes for a sizeof(int) bytes long bit pattern before determining
>>>whether it should return the next char as input or return EOF instead.
>>>Of course, in such a scheme, the system would need to be able to escape
>>>the bit pattern if it wanted to be able to scan the bytes literally.
>>>(We don't know how it is done, nor should we care.) >If you want a practical example, consider a stdio interface implemented
>over a compressed filesystem.


I still don't get it. Each and every byte combination is still valid
in a binary file, therefore it *cannot* be used as eof marker.


A trivial example would be an MS-DOS-like hybrid system on which the
byte 0xA1 would indicate the end of each file (text or binary). [Not
a typo; I specifically changed it from 0x1A so that EOF could be
#defined to be 0xA1A1 on this hypothetical 16-bit system.]
"But then how does a program represent the literal byte 0xA1 on
the disk?" you ask. Simple -- escape codes. For example, the EOF
code could be 0xA1A1, and the escape code for the literal byte 0xA1
could be 0xA100 (big-endian). This would satisfy all the requirements
of the C standard on file systems (i.e., precious few), while being
technically possible.


The semantics of fscanf and ftell on binary streams render this scheme
painful to implement: the byte offsets used by the program or reported
to the program are not the real byte offsets inside the file. But this
is only the tip of the iceberg. Imagine that I want to overwrite a
sequence of ordinary bytes by a sequence of 0xA1 bytes. Not only the
whole remaining of the file would have to be rewritten on the disk, but
the physical size of the file would increase, creating problems if there
is no more room on the disk (from the user's POV the file has the same
size, but it suddenly no longer fits on the disk). I'm afraid no one
would want to use your implementation ;-)

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 13 '05 #76
Arthur J. O'Dwyer wrote:
[In case Dan hasn't already thought of this: fseek() is not required
to run in constant time. Binary files don't have to be random-access
in their "natural state"; it just happens that all existing systems
do it that way.]


The file system used on some IBM mainframes does not make fseek() easy.

For files with fixed length records, they are normally stored on disk in
fixed length blocks, except for the last block. If an existing file is
appended to, it can have a short block that is not at the end, making
random access difficult. Though if the library routines keep track of
the block sizes the first time through, it would be easy to fseek() to
any previously seen position.

For files with variable length records (V or VB), the only way would be
to keep track of the block lengths in the file.

-- glen

Nov 13 '05 #77

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

Similar topics

7
1740
by: Christopher Richards | last post by:
It is possible to be able to receive email alerts (say, from Google News) and publish them to a web page automatically? I am a novice as far as PHP goes, but I can open and write to a file and close the file up again. The html page references the file and can format the plain text. So far I am OK ( I think ). I am not sure how I would automate, or get the content of the email, and output it to a file. Any thougths? Thank you.
2
1998
by: Ewa | last post by:
Hello I have inherited a www service after someone, I have problems with PHP parts. As I am complete novice. I will be very greatful for your help - I did not managed to find an answer myself. My questions are trivial, I guess. The service is now being moved to another server (PHP 4) and also I would like to run it on my local WAMP (PHP 5) for tests. 1. There's a directory defined there called php_base, which is the root
0
1499
by: gilgantic | last post by:
I am a novice a Security Models using Java. Could you recommend some web sites, books, or articles relating to build security models in a Java application. Any suggestion small or large is welcomed. Thanks!
5
2377
by: Marian | last post by:
Hi, I am totaly novice in .NET and I am studying a book about this. There was mentioned "assembly". I did not understand, how function does it has . I would like to know the exact run of code (intermediate language and so on). Is there any page on internet, which makes me clear? Thanx
2
2021
by: George | last post by:
Is this group for a novice C++ programmers?
4
1729
by: Tim Bird | last post by:
Hi all. I have recently installed VB2005 so teach myself programming, could anyone suggest any links to useful websites, or help sites, Ideally I am looking for tutorials, written for the complete novice TIA
1
1767
by: gretchen.ogrady | last post by:
I admit - I'm a simple user but looking to improve skills. Instructions aren't helping and have searched this group but am getting bogged down by some of the programming-speak. I have a query called PAL_PA Summary and in that query I calculate several fields, all %s: Fed, ITS, SALT which are 3 of the 6 columns for example. Basically its a query by person that shows the % of their time spent in these diff fields (they add up to 100%). ...
4
1661
by: trond | last post by:
Hello all, Before I start I'd like to point out that I am a complete novice when it comes to asp.net - My background is in network and operating systems, and although I have been doing a bit of hobby programming in vb.net and web programming in asp/vbscript in the past, I am pretty much a beginner at asp.net. What I'm trying to do, is to take the "PersonalHomePage" starter kit that MS supplies with VS2005 and tweak it a bit, to make it...
9
3067
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped. Below you will find the code I've written and the error that results. I'm hoping that someone can give me some direction as to what syntax or parameter is missing from the code that is expected by VBA. Overview: I'm trying to copy calculated...
5
1536
by: =?ISO-8859-2?Q?Istv=E1n?= | last post by:
Could somebody suggest me a novice Python list, please? Thanks, Istvan
0
9932
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9777
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10833
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9558
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5782
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5979
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3226
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.