读取和写入二进制文件中的缓冲区
这是我现在的代码:
#include <stdio.h>
#include "readwrite.h"
int main ()
{ FILE* pFile;
char buffer[] = {'x' ,'y','z',0};
pFile = fopen("C:\\Test\\myfile.bin","wb");
if (pFile ){
fwrite(buffer,1,sizeof(buffer),pFile);
printf("The buffer looks like: %s",buffer);
}
else
printf("Can't open file");
fclose(pFile);
getchar();
return 0;
}
我正在尝试编写一些内容来验证我写入文件,然后从文件中读取并验证我从文件中读取。如何最好地做到这一点?我还需要找到一种方法将相同的内容写入两个不同的文件。这可能吗?
Here is my code as of now:
#include <stdio.h>
#include "readwrite.h"
int main ()
{ FILE* pFile;
char buffer[] = {'x' ,'y','z',0};
pFile = fopen("C:\\Test\\myfile.bin","wb");
if (pFile ){
fwrite(buffer,1,sizeof(buffer),pFile);
printf("The buffer looks like: %s",buffer);
}
else
printf("Can't open file");
fclose(pFile);
getchar();
return 0;
}
I'm trying to write something verify i wrote to the file and then read from the file and verify i read from the file. How best is there to do this? I also need to figure out a way to write the same thing to 2 different files. Is this even possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你正在寻找这样的东西:
问候
I think you are looking for something like this:
Regards
读取缓冲区的程序几乎相同,除了“rb”用于读取二进制文件和
fread()
而不是fwrite()
请记住,您必须知道缓冲区有多大您将要读取 is 并准备好一些大小合适的内存来接收它
The program to read a buffer is almost the same except "rb" for read binary and
fread()
instead offwrite()
Remember you will have to know how big the buffer you are going to read is and have some memory of the right size ready to receive it