I want to write multiple structures to a single file. I used fwrite function and append mode. The writing process is done without any error. How can i read the specific structure. Which means if i want to read the third structure that i wrote to fi开发者_如何学Cle, how can i do it. I used fseek function and try to find the third position and read it using fread. But it didn't worked. Please can anyone help me.
FILE * pFile;
pFile = fopen ( "example.txt" , "rb" );
fseek ( pFile , sizeof(MyStruct)*2 , SEEK_SET );
MyStruct str;
fread(&str, sizeof(MyStruct), 1, pFile,)
When you use fwrite()
, use +a
tag
精彩评论