472,784 Members | 1,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 software developers and data experts.

What are the differences in EOF & FEOF in the

context of a C program reading from a file?

I know its end of file but ...not sure?
Apr 8 '08 #1
9 8290
2005 wrote:
context of a C program reading from a file?
Please don't ask your real question in the subject line.

FEOF is not mentioned in the C standard.
I know its end of file but ...not sure?
Get yourself a decent C text book. C is not a good
language to learn by asking 20 (000) questions.

--
Peter
Apr 8 '08 #2
On Apr 7, 11:06 pm, Peter Nilsson <ai...@acay.com.auwrote:
2005 wrote:
context of a C program reading from a file?

Please don't ask your real question in the subject line.

FEOF is not mentioned in the C standard.
I know its end of file but ...not sure?

Get yourself a decent C text book. C is not a good
language to learn by asking 20 (000) questions.

--
Peter
I do have several books - I saw a code online with EOF when reading
from a file.
That's why

I read the book too but would like a crisp answer

I appreciate a tip.
Apr 8 '08 #3
2005 said:

<snip>
I do have several books - I saw a code online with EOF when reading
from a file.
That's why

I read the book too but would like a crisp answer
K&R2 provides a crisp answer on page 16.
I appreciate a tip.
Here's a tip, then: read more.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Apr 8 '08 #4
On Apr 7, 11:47 pm, Richard Heathfield <r...@see.sig.invalidwrote:
2005 said:

<snip>
I do have several books - I saw a code online with EOF when reading
from a file.
That's why
I read the book too but would like a crisp answer

K&R2 provides a crisp answer on page 16.
I have K&R - not sure if there had been a "2"

EOF - a distinctive value when there is no more input, a value that
cannot be confused with any real character. This value is called
EOF, for ``end of file''.
FILE *in = fopen("myfile.txt", "r"); // Open myfile.txt read-only
while((myChar=fgetc(in)) != EOF) {
---------
---

feof is to distinguish between cases where a stream operation has
reached the end of a file and cases where the "EOF" (End Of File)
error message has simply been returned as a default error message,
without the end of the file actually being reached.

while(!feof(my_file)) {
/* [...End of file not reached, do something with it...] */
}
-----
--

So what is the difference when it comes to application?
Apr 8 '08 #5
2005 said:

<snip>
while(!feof(my_file)) {
/* [...End of file not reached, do something with it...] */
I sometimes despair of humanity.

while(file-reading-function doesn't
return an indication that data
could not be read - which may
well involve EOF, e.g. for
getchar, getc, fgetc)
{
process the data;
}

if(feof(my_file)
{
all the data was processed;
}
else
{
there seems to have been an input error - so check ferror()'s result.
}

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Apr 8 '08 #6
2005 wrote:
I have K&R - not sure if there had been a "2"

EOF - a distinctive value when there is no more input, a value that
cannot be confused with any real character. This value is called
EOF, for ``end of file''.
FILE *in = fopen("myfile.txt", "r"); // Open myfile.txt read-only
while((myChar=fgetc(in)) != EOF) {
---------
---

feof is to distinguish between cases where a stream operation has
reached the end of a file and cases where the "EOF" (End Of File)
error message has simply been returned as a default error message,
without the end of the file actually being reached.

while(!feof(my_file)) {
/* [...End of file not reached, do something with it...] */
}
-----
--

So what is the difference when it comes to application?
What do *you* think the difference is? Post your answer here, and we
will tell you if you are right or not, and if you are wrong, we will
tell you where your mistake is.

I suggest this for two reasons:

1) It is *much* more effective to learn by doing than by being lectured.
2) It's difficult to see which bit is confusing you. You have already
asked the difference between feof() and EOF, and Richard gave you this
answer. If you just ask the same question again, we don't know how to
make it any clearer.

Philip
Apr 8 '08 #7
2005 <FW****@sbcglobal.netwrites:
On Apr 7, 11:47 pm, Richard Heathfield <r...@see.sig.invalidwrote:
>2005 said:

<snip>
I do have several books - I saw a code online with EOF when reading
from a file.
That's why
I read the book too but would like a crisp answer

K&R2 provides a crisp answer on page 16.
I have K&R - not sure if there had been a "2"
K&R2 is the second edition. The first edition is mostly of historical
interest; it describes a largely obsolete version of the language. If
you have the first edition, invest in a copy of the second.
EOF
[snip]
feof is to
[snip]
So what is the difference when it comes to application?
The comp.lang.c FAQ is at http://www.c-faq.com. Read section 12.
Then read the rest of it.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Apr 8 '08 #8
2005 wrote:
Peter Nilsson <ai...@acay.com.auwrote:
>2005 wrote:
>>context of a C program reading from a file?
Please don't ask your real question in the subject line.

FEOF is not mentioned in the C standard.
>>I know its end of file but ...not sure?

Get yourself a decent C text book. C is not a good
language to learn by asking 20 (000) questions.

I do have several books - I saw a code online with EOF when
reading from a file.
Get yourself K&R2. Use it as the ultimate authority, barring the
actual C standard. Burn any books written by Herbert Schildt.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
** Posted from http://www.teranews.com **
Apr 9 '08 #9
On Tue, 08 Apr 2008 00:52:07 -0700, Keith Thompson <ks***@mib.org>
wrote:
2005 <FW****@sbcglobal.netwrites:
I have K&R - not sure if there had been a "2"

K&R2 is the second edition. The first edition is mostly of historical
interest; it describes a largely obsolete version of the language. If
you have the first edition, invest in a copy of the second.
Which you might be able to finance by selling K&R1 to a collector. <G>

And get the errata at http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html
- formerly david.thompson1 || achar(64) || worldnet.att.net
Jun 27 '08 #10

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

Similar topics

3
by: wenke | last post by:
Hi, I am using the following code (see below) from php.net (http://www.php.net/manual/en/ref.xml.php, example 1) to parse an XML file (encoded in UTF-8). I changed the code slightly so that the...
4
by: Robert Schott | last post by:
Hi .. this is for sure the 1k question on fopen but maybe can someone tell me this weird staff if i'm writing: $H = fopen($value,"r"); while(!feof($H)) { $string = fgets($H,1024); .... .......
2
by: Colin Bell | last post by:
I'm stuck on a problem with getting data from a XML data stream. This stream is large and trying to use fsockopen to get the stream down. I've tetsed the code by telneting into the machine/port...
7
by: Wolfgang Werners-Lucchini | last post by:
Hallo! The code here outputs '0'. Why? ---------------------------- $filename = "test.dat"; if (!file_exists($filename)) { touch($filename); // Create blank file chmod($filename,0666); }...
42
by: Andy | last post by:
and so far I'm loving it, I like the the authors don't beat around the bush and just come straight out and say what the book is sopposed to be. They assume the you have computer experience. I'm...
8
by: rCs | last post by:
Which of the following two approaches is preferred (and why)? int c; do { ... c = getchar(); } while (c != EOF); - or -
11
by: rsk | last post by:
Hi Friends, Can you plzz tell me whats wrong with this code. #include <stdio.h> #include <math.h> main () { FILE *fp;
24
by: kindrain | last post by:
the code checks whether a.txt has exact the same lines, then write different lines into b.txt Here it is: (before that ,you should creat a.txt) ---------------------- #include<stdio.h>...
9
by: Betikci Boris | last post by:
I get bored last night and wrote a script that uses xor for encrypt- decrypt, however it woks fine under linux 2.6.25, text and documents are ok, but fails on compressed files *.jpg, *.pdf , etc ....
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.