高分悬赏:C语言二进制文件读写问题。必有重谢!!!
发布网友
发布时间:2022-05-01 20:41
我来回答
共1个回答
热心网友
时间:2022-06-23 01:15
#include<stdio.h>
#include<stdlib.h>
char *srcfile = "src.bin";
char *objfile = "obj.txt";
typedef char byte;
int main()
{
FILE *src = fopen(srcfile,"r");
if(src == NULL)
{
printf("Can't open the src file!\n");
exit(1);
}
system("rm obj.txt");
FILE *obj = fopen(objfile,"w");
if(obj == NULL)
{
printf("Can't create the obj file!\n");
exit(1);
}
byte b;
while(!feof(src))
{
fscanf(src,"%c",&b);
fprintf(obj,"%c",b);
if(feof(src))
break;
fscanf(src,"%c",&b);
fprintf(obj,"%c\n",b);
}
return 0;
}