如果我明确声明缓冲区大小,我似乎只能将文件读入内存。这有效
#include <stdio.h>
int main(){
FILE *fp = fopen("test.log", "rb");
char buffer[37];
fread(buffer, 1, 36, fp);
printf("%s", buffer);
}
这会将垃圾添加到输出中
#include <stdio.h>
int main(){
FILE *fp = fopen("test.log", "rb");
fseek(fp, 0, SEEK_END);
long siz = ftell(fp);
rewind(fp);
char buffer[siz + 1];
fread(buffer, 1, siz, fp);
printf("%s", buffer);
}