C语言文件操作实例:读写二进制文件test2.dat
#include <stdio.h> #include <stdlib.h>
int main() { int a1, a2; float f1, f2; FILE *fp1, *fp2;
fp1 = fopen('test2.dat', 'wb');
if (fp1 == NULL) {
printf('Can't open file!\n');
exit(1);
}
scanf('%d,%f', &a1, &f1);
fprintf(fp1, '%d,%f', a1, f1);
fclose(fp1);
fp2 = fopen('test2.dat', 'rb');
if (fp2 == NULL) {
printf('Can't open file!\n');
exit(1);
}
fscanf(fp2, '%d,%f', &a2, &f2);
printf('保存的用户输入数据是%d,%f', a2, f2);
fclose(fp2);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/pkpw 著作权归作者所有。请勿转载和采集!