Copy parts of a buffer in C -
gang, doing wrong, wanting take specific offset + length of data out of file , copy allocated buffer of same length...
if( stru_ct->size != 0 ){ unsigned char * s_buffer = malloc(stru_ct->size); if( !s_buffer ){ printf( "memory error!" ); return -1; } fseek( file, wp->stru_ct->offset, seek_set ); fread( s_buffer, stru_ct->size, 1, file ); }
there's no compilation error, s_buffer still results in 0 after fread. know there's data @ offset + length.
thanks help!!
check return values fseek()
, fread()
make sure they're not failing. never assume call make has succeeded.
Comments
Post a Comment