开发者

Finding the location of data write using fwrite function in C

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜