----------------解决方案--------------------------------------------------------
对于大数据块,适宜用fwrite()写入二进制文件;
楼主似乎不是这种情况,直接用fprintf()就搞定了。
----------------解决方案--------------------------------------------------------
#include<string.h>
main( )
{
char s[]="zhongguo",t[40]={0}; //必须清零
long d1=123456, d2=0L;
FILE *fp=fopen("c:\\my_test.bin","wb");
fwrite(s,sizeof(char),strlen(s),fp);
fwrite(&d1,sizeof(long),1,fp);
fclose(fp);
/*测试以上代码的实际效果:*/
fp = fopen("c:\\my_test.bin","rb");
fread(t,sizeof(char),strlen(s),fp);
fread(&d2,sizeof(long),1,fp);
fclose(fp);
printf("%s\n%ld\n",t,d2);
}
"d2=0L"是什么意思啊?
[[italic] 本帖最后由 warmsnake323 于 2007-12-21 16:29 编辑 [/italic]]
----------------解决方案--------------------------------------------------------