开发者

Finding the location of data write using fwrite function in C

开发者 https://www.devze.com 2023-03-10 10:19 出处:网络
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 wan

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

精彩评论

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