How to read null characters in a file

A

asvini

Hi
I want to read a file which has data and null characters in
between...
But my program terminates on encountering NULL characters...is there
any other way to read the whole file with the NULL characters..

thanks in advance...
regards
asvini
 
R

Random832

2006-12-23 said:
Hi
I want to read a file which has data and null characters in
between...
But my program terminates on encountering NULL characters...is there
any other way to read the whole file with the NULL characters..

Write a program that doesn't terminate on encountering null characters.
 
R

Richard Tobin

asvini said:
I want to read a file which has data and null characters in
between...
But my program terminates on encountering NULL characters...is there
any other way to read the whole file with the NULL characters..

You haven't described your program enough for anyone to be sure what
your problem is, but a common mistake is to use fgets() and treat the
result as a (null-terminated) string. This obviously won't work if
there may be nuls in the data. You can use fread() or getc() instead.

Also, make sure you are opening the file in binary mode.

-- Richard
 
D

Default User

asvini said:
Hi
I want to read a file which has data and null characters in
between...
But my program terminates on encountering NULL characters.

Which program is that? How can we possibly diagnose something that you
don't show us?




Brian
 

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

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,690
Members
48,796
Latest member
Greg L.

Latest Threads

Top