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

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -