473,698 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

feof(), fseek(), fread()

If fseek() always clears EOF, is there a way for me to fread() from an
offset of a file and still be able to detect EOF?i.e. withouting using
fseek(). I also need to seek to an offset in the file
frequently(forw ards and backwards) and do fread() from that offset.

Or better still, could anyone let me know some good ways to achieve
what I need to do as above?Can I get hold of the file and being able
to read in without using fread()? Using memory addresses?
Thanks

Mar 24 '07
20 7532
ericunfuk <xu***********@ gmail.comwrote:
>in my understanding, fread() would not encounter the original
end-of-file it will read beyond x and no error(even EOF) will happen?
The question is, are you calling fread() anywhere past the end of the
file?

If the answer is yes, then feof() will return non-zero right after that.

Think of it this way: end-of-file is not something you cross like a
border. It's a place that you either are in, or are not in.

You're trying to fool the end-of-file flag by calling fseek() to clear
the flag before calling fread() past the end of the file. But it won't
work, because fread() will see that it is once again past the end of the
file, and it will just set the end-of-file flag again!

-Beej

Mar 24 '07 #11
On 23 Mar 2007 18:47:49 -0700, in comp.lang.c , "ericunfuk"
<xu***********@ gmail.comwrote:
>On 24 Mar, 01:40, Ben Pfaff <b...@cs.stanfo rd.eduwrote:
>"ericunfuk" <xuwenduan2...@ gmail.comwrites :
If fseek() always clears EOF, is there a way for me to fread() from an
offset of a file and still be able to detect EOF?

Please explain how the several previous answers to your several
previous similar questions are inadequate.
>I still don't know how can I detect EOF
By readin the previous answers. All the IO functions return status
messages which will tell you when you found the end of a file.
>I must be able to seek forwards and
backwards in the file, but I still don't know up to now how can I do
this without fseek(), that's why I posted this question.
You can do it with fseek, thats what its for. However its up to you to
ensure your seeks remain inside the file by some other means. A
trivial way to do this is to determine the file size never seek
further than that from the start of the file.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mar 24 '07 #12
On 23 Mar 2007 19:44:55 -0700, in comp.lang.c , "ericunfuk"
<xu***********@ gmail.comwrote:
>
>After fseek(), call fread() to read data. If it returns a short
>--
Ben Pfaff
b...@cs.stanfo rd.eduhttp://benpfaff.org

How about fseek() already seeked over EOF before I invoke fread(), and
it could cleared EOF, so feof() or ferror() won't work anymore?
For goodness' sake. When did anyone say that fseek erased the EOF flag
eternally? Each function will set it, if and only if, it encounters
the end of the file.

You still think EOF is the end of hte file don't you?
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mar 24 '07 #13
ericunfuk wrote:
On 24 Mar, 01:40, Ben Pfaff <b...@cs.stanfo rd.eduwrote:
>"ericunfuk" <xuwenduan2...@ gmail.comwrites :
>>If fseek() always clears EOF, is there a way for me to fread() from an
offset of a file and still be able to detect EOF?i.e. withouting using
fseek(). I also need to seek to an offset in the file
frequently(fo rwards and backwards) and do fread() from that offset.
Please explain how the several previous answers to your several
previous similar questions are inadequate.
--
"A lesson for us all: Even in trivia there are traps."
--Eric Sosman

I still don't know how can I detect EOF while I'm always use fseek()
(It always clears EOF), and I must be able to seek forwards and
backwards in the file, but I still don't know up to now how can I do
this without fseek(), that's why I posted this question.
Some part of your C education has been missed. First, EOF is a macro
defined in stdio.h probably as..

#define EOF (-1)

...It has a negative value of type int. You keep talking about fseek()
clearing EOF. Wrong. Nothing about EOF can be cleared.

Within the file system there is there is presumably an indicator
associated with the feof() function to tell us whether the file pointer
(no, not FILE pointer) is at the end of the file. For sake of this
discussion, let's call the flag eof (not EOF, which is a macro). This
flag ivolves itself with attempts to read past the end of file with
fgetc(), fgets(), etc. fseek() has nothing to do with reading from a
file. There is nothing that fseek() can do that ought to set the eof flag.

If you would navigate within the file you can know its bounds (as
offsets into the file) with two commands..

long eoff;
fseek(fp, 0, SEEK_END);
eoff = ftell(fp);

File offsets are now 0 to (not including) eoff, which is one past your
playground. You can't seek past eoff. Attempts to do it will fail.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Mar 25 '07 #14
In article <Ub************ *************** ***@comcast.com >,
Joe Wright <jo********@com cast.netwrote:
>If you would navigate within the file you can know its bounds (as
offsets into the file) with two commands..
long eoff;
fseek(fp, 0, SEEK_END);
eoff = ftell(fp);
>File offsets are now 0 to (not including) eoff, which is one past your
playground.
If fp is a binary stream, then SEEK_END might not be meaningfully
supported on it. (An example for unixoids: where would SEEK_END
put you for /dev/zero ?)

If fp is a text stream, then your eoff is an opaque token that need
not correspond to an integral file position. Seeking in a text stream
has to take into account end of line translation, so even if the value
turns out to be integral, it might not correspond to the number of
characters that one would getc() to reach that point in the file.

>You can't seek past eoff. Attempts to do it will fail.
There is nothing in the C89 standard preventing you from seeking past
the end of file -- the matter is not discussed there. And if you happen
to be in a POSIX.1 environment, then seeking past end of file is well
defined, specifically discussed and okayed in the POSIX.1 description
of (POSIX's) lseek() .
--
If you lie to the compiler, it will get its revenge. -- Henry Spencer
Mar 25 '07 #15
Joe Wright <jo********@com cast.netwrites:
[...]
Some part of your C education has been missed. First, EOF is a macro
defined in stdio.h probably as..

#define EOF (-1)

..It has a negative value of type int. You keep talking about fseek()
clearing EOF. Wrong. Nothing about EOF can be cleared.

Within the file system there is there is presumably an indicator
associated with the feof() function to tell us whether the file
pointer (no, not FILE pointer) is at the end of the file. For sake of
this discussion, let's call the flag eof (not EOF, which is a
macro). This flag ivolves itself with attempts to read past the end of
file with fgetc(), fgets(), etc. fseek() has nothing to do with
reading from a file. There is nothing that fseek() can do that ought
to set the eof flag.
Your terminology here is potentially ambiguous.

Though the C standard doesn't use the phrase "file system", that
phrase commonly refers to the operating system infrastructure that
supports external files (typically on disk). It's sometimes written
as a single word, "filesystem ".

What you mean by the term, I think, is the code in the C runtime
environment that implements the functions declared in <stdio.h>.

There is a flag associated with each stream that "records whether the
end of the file has been reached". The standard calls this the
"end-of-file indicator" (C99 7.19.1p2). I suggest that inventing
another name "eof flag" for this is not helpful.

What you refer to as a "file pointer" is what the standard calls the
"file position indicator". A stream also has an "error indicator"
associated with it.

[snip]

--
Keith Thompson (The_Other_Keit h) 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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 25 '07 #16
>File offsets are now 0 to (not including) eoff, which is one past your
>playground. You can't seek past eoff. Attempts to do it will fail.
Attempts to seek past the existing size of a file do not fail on
all systems. It is possible to create a file with a "hole" in it
on many UNIX systems by opening the file, seeking to an offset of
1GB, and writing one byte. The initial part of the file reads as
a lot of zero bytes. Further, sometimes that file will fit on a
floppy disk much, much smaller than the apparent size of the file.
Mar 25 '07 #17
In article <ln************ @nuthaus.mib.or g>
Keith Thompson <ks***@mib.orgw rote:
>There are several different entities covered by the terms "EOF" and/or
"end-of-file", and I think [the OP is] mixing them up.
Indeed.
>1. EOF is a macro that expands to a constant integer expression. ...
2. The end of a file is simply the position in the file at which it
ends, depending on its current size.
3. An "end-of-file indicator" is an internal flag associated with a
stream. ...
Those are all we have in C, anyway. In actual implementations we
may also have an "EOF character", just to confuse the issue further.
(More on that later.)
>These are three entirely different things.
As is the fourth, alas.
>A "stream" is an entity in your executing program that's associated
with an external file. The file exists outside your program,
typically sitting on a disk somewhere (though there are a myriad of
other possibilities).
It is worth mentioning at least two of the other possibilities,
since they normally occur when running any C program (on a hosted
system anyway). An input stream can be connected to the user's
keyboard ("stdin"), or to the user's output screen/window/whatever
("stdout" and "stderr" both, normally).

The OP may (or may not) find some help by stepping outside the C
language for a while. I think he mentioned something about Linux
at one point, although for my purposes here, Linux, Unix, or even
Windows would all be similar enough. (Something like VMS or TSO
would not.)

If we put C aside for a while, we can ignore the whole concept of
a "stream". Here, a "file" is simply an on-disk entity. It is
definitely *not* something interactive like a keyboard or screen,
nor a communications channel to a remote computer like a socket.
(Unix-like systems attempt to make those special things act a lot
like disk files, with varying degrees of success. But we want to
ignore those too.)

Now, given an on-disk file, of whatever size, the OS has some way
of letting you "open" the file, then poke around in the contents.
A Unix-like system does this with the open(), read(), and lseek()
functions (none of which are Standard C, remember; they just happen
to be there, with known behavior, on the Unix-like systems).

When you open() a file, you get a small integer number called a
"file descriptor". There is *no* "end of file indicator" associated
with this descriptor, but there is a "current position within file"
associated with it. The current position is initially 0.

To move the current position (without doing anything else), you
use lseek().

To read data starting at the current position, you use read(). You
give read() three numbers: a file descriptor, a pointer to a buffer,
and a number of bytes. The descriptor identifiers the file and
carries the current lseek() offset. The buffer pointer tells the
OS where to copy the file data. The number of bytes tells the OS
how many bytes to read from the file, into that buffer:

int fd, result;
char buf[SIZE];
...
result = read(fd, buf, SIZE);

If the read is completely, totally, 100% successful, then:

- "result" is set to SIZE;
- the successfully-read bytes are put in buf[0] through buf[SIZE-1]; and
- the current lseek() position is moved forward SIZE bytes.

If the read fails entirely for some reason -- e.g., if the file is
on a floppy disk and the disk has gone bad -- the call returns -1:

- "result" is set to -1;
- the contents of buf[] may or may not be garbage[%];
- the variable "errno" is set to indicate the underlying error
(usually EIO, but maybe something else depending on the OS); and
- the current lseek() position does not change.

[% The buffer contents tend to depend on whether the OS uses DMA
and how the hardware behaves when the bad floppy reports its
bad-ness.]

There is a third possibility as well, though. Suppose that SIZE
is 100, the current offset is 200, and the file is only 220 bytes
long. In this case, there are only 20 bytes remaining in the file.
This read() call needs to "partly succeed" and "partly fail". How
can read() report "partial success"?

The answer is: if -1 means "error" and 100 means "total success",
then any number *between* those two means "partial success". The
exact *amount* of success is given by the number. In this case,
since there are 20 bytes left, the read() will return 20:

- "result" is set to 20;
- the successfully-read bytes are put in buf[0] through buf[19]; and
- the current lseek() position is moved forward 20 bytes.

In other words, "partial success" looks EXACTLY THE SAME as "total
success", except that the count is less than the number of bytes
you asked for.

Now, what happens if the current position is at, or even *beyond*,
the end of the file? One option -- one that was used in some OSes
before Unix -- is to report this as an "error". Unix could have
done that: it could have returned -1, and set errno to EEOF or some
such. This is not how Ken Thompson decided to do it, though.
Instead, he had the read() report "partial success", with the number
of bytes successfully read being zero. If read() calls this "partial
success" and reports zero bytes read, then:

- "result" is set to 0;
- the successfully-read bytes are not put anywhere (because
there are none), so buf[] is left unchanged; and
- the current lseek() position is moved forward 0 bytes,
which leaves it unchanged.

So, if one uses the low-level calls (open(), optionally lseek(),
read(), and close()) on a Unix-like system, one simply checks the
return value from each read() call: -1 means error, 0 means "end
of file", and any other value means "success", with the successful
count being very important, since it may be less than you asked
for.

Now, the reason for all of this "off-topic drift", as it were, is
because C's stdio was originally designed to "wrap around" the Unix
I/O model, but also allow for the more obnoxious I/O models found
on other systems available at the time.

In C, instead of a "file descriptor", you get a "stream". On a
Unix-like system, a stream is a pretty thin wrapper around the
underlying file descriptor. On other systems, it may be much
"thicker", hiding all kinds of system-level obnoxiousness, such as
different I/O routines for "interactiv e" streams (keyboard and
display) from "disk" streams (on-disk files). (Yes, other OSes
really do require different OS calls to do I/O on files vs devices.)

In any case, however, a "stream" still has, as an underlying concept,
a "current seek position". On a Unix-like system, this position
-- which you manipulate with fseek() -- is exactly the same thing
as the descriptor's byte offset, which the library manipulates with
lseek(). On more-obnoxious systems, though, the "fseek position"
may have little or even no resemblance to a byte offset. (In fact,
on some VMS systems, the values returned by ftell() are derived
from pointers obtained by malloc(). Each ftell() does a new malloc()
to remember exactly where you are in the file now, so that the full
positioning information can be passed to RMS and/or the SYS$QIO OS
calls.)

Now, fread() could have used a trick similar to Unix's read(): it
could return a short count for end-of-file, and -1 for error. But
there is one problem: fread() returns a size_t, which is an *unsigned*
integer. There is no "-1". So fread() returns zero for both
"encountere d end of file" and "encountere d error".

Similarly, fgetc() could have used a trick to report "end of file"
and "error" separately. In this case, fgetc() -- and getc() and
getchar(), which are defined in terms of fgetc() -- returns a value
in [0..UCHAR_MAX] on success. If UCHAR_MAX is 255 (as it usually
is), that means there are 256 "successful " values. Since fgetc()
returns an ordinary "int", and an "int" has to be able to count
negative numbers from -1 to -32767 (if not more), there are *plenty*
of extra values to use. But -- for some reason (I have no idea
what reason) -- the guys who wrote the original implementations
chose to report both "end of file" and "error" with a single return
value, just like fread().

As Keith wrote above, the value fgetc() returns, to indicate any
kind of failure -- "end of file" failure, or "error reading disk"
failure, or whatever -- is the one defined in <stdio.h>. On most
implementations , the value fgetc() returns for these failures is
-1. The C Standard requires only "a negative int value", and that
<stdio.hdefin e EOF to that particular negative value, but most
implementors use -1.

This is where the "end of file indicator" on the stream -- Keith's
item #3 -- comes in. Both fread() and fgetc() fail to distinguish
between the two "failure" cases. (These cases, remember, are:
"(A) You asked me to read, but I failed to read anything because,
while everything is all still working fine, there is nothing left
to read!" and "(B) You asked me to read, but I failed to read
anything ... and by the way, look out, the floppy disk is on fire!")

The guys who wrote the C "standard I/O" library decided to allow
you -- the C programmer -- to be able to distinguish between
these two cases, using the feof() and ferror() macros:

FILE *fp;
...
... attempt to read something from the file ...
if (our attempt to read failed) {
if (feof(fp))
printf(
"this was case (A): read failed, but all is well;\n"
"this was just the normal end of file.\n");
if (ferror(fp))
printf(
"this was case (B): read failed, and something is\n"
"badly wrong. Better check: is the disk on fire?\n");
} else {
... our attempt to read worked; use the data ...
}

The tricky bits with feof() and ferror() are:

1) These are "after-the-fact flags", not "prediction s about the
future". You should only use the macros to test *why* a
read operation failed, after one has *actually failed*.

2) Once one or both of these flag is/are set, they *stay* set
until you, the C programmer, take action to clear them. There
are a number of ways to clear them, including the clearerr()
function. The clearerr() function clears both of them without
doing anything else. It does not correct the underlying
problem (e.g., put out the fire, in case (B)). But if you
have some way of correcting it, you can do that, and then do
clearerr(), and then try your read() again.

One of the many things confusing the OP is that the fseek() function
clears the end-of-file indicator -- the flag that feof() tests --
whenever the fseek() succeeds. It does so even if the fseek() puts
the current seek position at or beyond the actual end of the actual
on-disk file (assuming, as always, that there is in fact an actual
on-disk file involved).

The rule here, then, is the same as always: try to do the I/O,
and pay attention to the return value from your I/O function:

if (fseek(fp, newpos, SEEK_SET)) ... do something about failure ...

result = fread(buf, item_size, number_of_items , fp);
if (result == 0) {
if (feof(fp))
... fread() failed due to normal, ordinary EOF ...
else
... fread() must have failed due to serious problem ...
} else {
... work with the data: fread() got "result" items ...
}

or:

if (fseek(fp, newpos, SEEK_SET)) ... do something about failure ...

result = fgetc(fp);
if (result == EOF) {
if (feof(fp))
... fgetc() failed due to normal, ordinary EOF ...
else
... fgetc() must have failed due to serious problem ...
} else {
... work with the data: fgetc() got the byte in "result"
}

Beginners can use a simple rule: NEVER call feof(). NEVER, EVER.
Just look at the return value from fread() or fgetc() or whatever.
Assume that "read failed" means "normal end-of-file", i.e., that
disks never catch on fire (and, more practically, that no one
ever uses a magnet to put the floppy up on the fridge).

More-advanced C programmers can move on to the more-advanced rule:
use feof() (and ferror()) ONLY after a read operation (fread, fgetc,
etc) has failed. (People actually do stick magnets on floppies,
or take the floppy out of its "wrapper", or hammer more than one
into a drive, or any number of other bone-headed stunts.)

Now, about that fourth item, the "EOF character" ... if it even
exists. This is another OS-specific thing.

Consider the Unix-like system, in which keyboard input is "just
like" an ordinary file. You open() the keyboard ("/dev/tty" or
"/dev/console" perhaps), or -- more simply -- get the file descriptor
handed to you in the usual way. You call read() to get input.
What if the user wants to signal "end of input"? He has to get
your read() call to return 0. How can he do that?

On a Unix system, the trick is to input the "EOF character" at
the start of a line (i.e., after pushing the RETURN or ENTER key).
This "EOF character" is usually control-D, but is changeable.

The same technique applies to Microsoft's DOS and Windows systems,
except that the key is different: you use control-Z instead of
control-D. But here things get even weirder.

On very old MS-DOS systems, and systems that predated MS-DOS, *disk*
files had a peculiar problem: they did not have a "size" associated
with them. Instead of a "size", they had a "number of disk sectors".
A disk file was 0 sectors long, or 1 sector long, or 2 sectors, or
3 or 4 or whatever. If a disk sector was 512 bytes (though 128
and 256 were also common), then a disk *file* could be 0 bytes, or
512 bytes, or 1024 bytes, or 1536 bytes, or 2048 bytes, and so on
-- but no disk file could ever be just 20 bytes. It had to be at
least "one sector", if it had any bytes at all.

So, on these systems, how could you mark the end of a text file?
The answer was: pick a character, call it the "end of file" character,
and write that somewhere in the last sector. When reading the
file, if you encounter that character, pretend that there is no
more data in the file, even if there really is more.

The "EOF character" in these disk files was usually control-Z (this,
incidentally, is why MS-DOS and Windows use control-Z as a keyboard
"EOF" character). Some I/O routines might detect ^Z as EOF only
in the *last* sector, while others would detect it in *any* sector
(though the latter took less machine code, and with every byte
being precious, this was certainly more common). The fact that
this sort of "EOF character" exists is part of the reason that you
have to fopen() a binary file with "rb" to read it. (It is not
the whole reason, but it is part of the reason.) If you fopen()
with just plain "r", a control-Z byte in the stream may -- or may
not -- cause your stdio to report "end of file".
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Mar 26 '07 #18
Chris Torek <no****@torek.n etwrites:
In article <ln************ @nuthaus.mib.or g>
Keith Thompson <ks***@mib.orgw rote:
>>There are several different entities covered by the terms "EOF" and/or
"end-of-file", and I think [the OP is] mixing them up.
[snip]

An excellent amplification, as usual. On small point:
On very old MS-DOS systems, and systems that predated MS-DOS, *disk*
files had a peculiar problem: they did not have a "size" associated
with them. Instead of a "size", they had a "number of disk sectors".
A disk file was 0 sectors long, or 1 sector long, or 2 sectors, or
3 or 4 or whatever. If a disk sector was 512 bytes (though 128
and 256 were also common), then a disk *file* could be 0 bytes, or
512 bytes, or 1024 bytes, or 1536 bytes, or 2048 bytes, and so on
-- but no disk file could ever be just 20 bytes. It had to be at
least "one sector", if it had any bytes at all.

So, on these systems, how could you mark the end of a text file?
The answer was: pick a character, call it the "end of file" character,
and write that somewhere in the last sector. When reading the
file, if you encounter that character, pretend that there is no
more data in the file, even if there really is more.

The "EOF character" in these disk files was usually control-Z (this,
incidentally, is why MS-DOS and Windows use control-Z as a keyboard
"EOF" character). Some I/O routines might detect ^Z as EOF only
in the *last* sector, while others would detect it in *any* sector
(though the latter took less machine code, and with every byte
being precious, this was certainly more common). The fact that
this sort of "EOF character" exists is part of the reason that you
have to fopen() a binary file with "rb" to read it. (It is not
the whole reason, but it is part of the reason.) If you fopen()
with just plain "r", a control-Z byte in the stream may -- or may
not -- cause your stdio to report "end of file".
I assume this kind of behavior is also why an implementation is
allowed to append arbitrarily many null characters to the end of a
binary file.

When you write or read a file in text mode, the physical contents of
the file may have to be translated in various ways. Those
translations may not give you back the same thing you wrote. (For
example, if you explicitly write a control-Z character to a text file,
you may not see that same character when you read the same file;
instead, it may mark the effective end of the file, even if you had
written more data after it).

When you write or read a file in binary mode, you get back exactly
what you wrote -- *except* that an implementation-defined number of
null characters may be appended to the end of the stream. This is why
fseek with with whence == SEEK_END isn't necessarily meaningful
(though it is under, for example, Unix).

--
Keith Thompson (The_Other_Keit h) 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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 26 '07 #19
On Sun, 25 Mar 2007 22:52:04 -0700, in comp.lang.c , Keith Thompson
<ks***@mib.orgw rote:
>Chris Torek <no****@torek.n etwrites:
>On very old MS-DOS systems, and systems that predated MS-DOS, *disk*
files had a peculiar problem: they did not have a "size" associated
with them. Instead of a "size", they had a "number of disk sectors".

I assume this kind of behavior is also why an implementation is
allowed to append arbitrarily many null characters to the end of a
binary file.
At least as likely it was due to VMS - all files are multiples of 512
bytes long, padded with nulls as required. Text files had ascii 26 to
mark the 'end' but the OS still considered a 12-byte file to be 512
bytes in size.

BTW isn't the file management family tree VMS->CPM->DOS?
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mar 26 '07 #20

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

Similar topics

3
2435
by: deko | last post by:
I'm trying to control the size of a log file. When it gets more than 5k oversize, I attempt to trim it thusly: $fcap = intval(($dval * 0.0108))*1024; // what it should be $fsize = filesize($file); // what it is $oversize = $fsize - $fcap; if ( $oversize > 5120 ) // 5k oversize { $fp = fopen($file,"r+");
10
5969
by: Kenneth Brody | last post by:
I recently ran into an "issue" related to text files and ftell/fseek, and I'd like to know if it's a bug, or simply an annoying, but still conforming, implementation. The platform is Windows, where text files use CF+LF (0x0d, 0x0a) to mark end-of-line. The file in question, however, was in Unix format, with only LF (0x0a) at the end of each line. First, does the above situation already invoke "implementation defined" or "undefined"...
14
3702
by: Maria Mela | last post by:
Hello everyone... I´ve a problem with my code, when i put this lines: recsize = sizeof(p1); fseek(fp,-recsize,SEEK_CUR); fwrite(&p1,sizeof(p1),1,fp); getch(); The file was saved with correct values and with some windows informations too!?
6
6149
by: ericunfuk | last post by:
A basic question: When the documentation says "fseek() clears EOF indecator, does it mean when you seek over EOF, EOF is no longer at the original position and hence removed?Say, after I seek over the original EOF, when I fread() from a previous position that I know is before the EOF then fread will not be able to tell if it has encountered the original EOF? Thank YOU!
6
3742
by: ericunfuk | last post by:
I have posted a few other posts before this one today, I still can't solve my problem, I think I need to elaborate my problem now. I'm trying to send a file using UDP, below is a segment of my sender app, the sender and the receiver are both on the same machine and I have an Internet emulation gateway running on the same machine as well. What I'm confused about is I can't detect when the end of the file I'm sending has been reached,...
7
5914
by: ahmetbm | last post by:
Hi; I have a c program that uses mpi library to run on parallel arhitecture. First i coded serial program and it worked perfectly. But the parallel one did not run. I found the error but could not solve it. The error is: the "fseek" and "fread" functions does not return the correct values. fseek(wav_fp,40L,SEEK_SET);fread(&str,4,1,wav_fp); this code must return "str" = "81913" but i get "-442495" Thanks.
13
4492
by: thomas.mertes | last post by:
Hello Recently I discovered some problem. I have some C code which determines how many bytes are available in a file. Later I use this information to malloc a buffer of the correct size before I read the bytes. Determining the number of bytes available in a file is done in 5 steps: 1. Use tell(aFile) to get the current position.
24
6003
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> #include<string.h> void main(){ FILE *fp,*ftemp;
0
8683
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
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7740
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...
1
6528
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
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
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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 we have to send another system
3
2007
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.