Problem with fread

Eljay Love-Jensen eljay@adobe.com
Tue May 20 13:23:00 GMT 2003


Hi Ajay,

fread does not append a '\0' (null character) at the end of a buffer.

Regarding your test_fread.cpp attachment...

You shouldn't use #include <string.h>, you should use #include <cstring>.

You shouldn't use #include <stdlib.h>, you should use #include <cstdlib>.

You shouldn't use #include <errno.h>, you should use #include <cerrno>.

I strongly urge you to consider using string objects and the #include 
<string> header, instead of fixed character buffers.

I strongly urge you to use fstreams and #include <fstream>, instead of 
FILE, fopen, stat, et al.

I strongly urge you to use C++ new/delete instead of C 
malloc/calloc/realloc/free.

I'll send you my refactoring of your test_fread.cpp shortly.  (Not to the 
forum.)

Sincerely,
--Eljay



More information about the Gcc-help mailing list