[ back to toc ]

Data manipulation in binary file

Date: 2002/04/22 13:58


I'm currently doing a project on JPEG file under Linux by using C. I'm
having a problem on this:

I use fdopen() to associate a sock stream with a FILE pointer and perform
fread() on it. Indeed, the data I read is binary JPEG content, the sock
stream contains many JPEG files, one following the others. Within each
JPEG image, there r a header and footer serve as the markings of the
beginning and ending of a single file. I fread() the content into a buffer
of the size of 15kB, and perform strstr() to search for the two markings.
It is strange that the header's address < footer's address, and when I do
arithmatic operation on these values, it returned '-39' (impossible!!!
each image must has the size around 12kB). So how can I calculate the
actual number of bytes within these keywords, so I can supply the
calculation result to fwrite() in order to copy the content to a file?

What I intend to do is to receive the JPEG stream from the socket, and
save each JPEG content within the markings into files (img000.jpg,
img001.jpg and so on).

For ur info, i'm using RedHat + SunSparc.

Because JPEG files are binary files that can contain arbitrary data it is
not save to try to find some marker before and after the content as the
content itself can contain the marker. Most probably this is the issue.


[ back to toc ]