看程序:
#include<stdio.h>
int main()
{
int a = 9;
int len = sizeof(a);
FILE *fp1 = fopen("log1", "w");
fprintf(fp1, "%d", a);
fclose(fp1);
FILE *fp2 = fopen("log2", "wb");
fwrite(&a, len, 1, fp2);
fclose(fp2);
return 0;
}
用ultraEdit观察log1和log2, 发现:log1比log2小。
看程序:
#include<stdio.h>
int main()
{
int a = 999999;
int len = sizeof(a);
FILE *fp1 = fopen("log1", "w");
fprintf(fp1, "%d", a);
fclose(fp1);
FILE *fp2 = fopen("log2", "wb");
fwrite(&a, len, 1, fp2);
fclose(fp2);
return 0;
}
用ultraEdit观察log1和log2, 发现:log1比log2大。
可见,在极为特殊的情况下,二进制文件占的空间更大,在大多数情况下,文本文件占的空间更大。