EOF character

L

Lew Pitcher

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,

my text file contains many lines of text, some of the text contains EOF
character appended at the end of the text.

if I use:
while (fgets(buffstr, sizeof(buffstr), in_ptr)!=NULL), it will only reach
the first text that contains the EOF character, not to the end of the file.

How can run through the whole file to the end instead, in order to do some
own filtering process?

Open the file in binary mode

file = fopen("filename","rb");


- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBlBduagVFX4UWr64RAj+GAJ413pho75KMip4OcwnSJDbLa7DgAgCeN5Nw
FJRVpSVRuEX/crmcoZNw2Jk=
=Lg7Q
-----END PGP SIGNATURE-----
 
M

Magix

Hi,

my text file contains many lines of text, some of the text contains EOF
character appended at the end of the text.

if I use:
while (fgets(buffstr, sizeof(buffstr), in_ptr)!=NULL), it will only reach
the first text that contains the EOF character, not to the end of the file.

How can run through the whole file to the end instead, in order to do some
own filtering process?

Thanks.
 
C

Christian Staudenmayer

The fgets() function is used for dealing with textfiles. What you want is the read() function (used together with open()), and you want to supply it with the "b" option for binary (see the manpage of read() for details).

Greetings, Chris
 
M

Magix

Lew Pitcher said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Open the file in binary mode

file = fopen("filename","rb");



- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBlBduagVFX4UWr64RAj+GAJ413pho75KMip4OcwnSJDbLa7DgAgCeN5Nw
FJRVpSVRuEX/crmcoZNw2Jk=
=Lg7Q
-----END PGP SIGNATURE-----

Thanks.
 
M

Martin Ambuhl

Christian said:
The fgets() function is used for dealing with textfiles. What you
want is the read() function (used together with open()), and you want
^^^^ ^^^^
You misspelled both fread() and fopen()
to supply it with the "b" option for binary (see the manpage of
^^^^^^^
You misspelled "your documentation"
read() for details).
^^^^
Again, misspelling fread()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top