FILE *infp, *outfp;
infp = fopen(argv[2], "r");
int len;
char *text;
fseek(infp, 0, SEEK_END);
len = ftell(infp);
printf("%d\n", len);
if ((text = (char *) malloc(500000000)) == NULL)
{
fprintf(stderr, "Error allocating memory\n");
exit(1);
}
fread(text, len, 1, infp);
text[len] = '\0';
fclose(infp);
printf("Text = %s, Address = %u\n", text, text);
138
Text = , Address = 3794927632
我不知道为什么文本不打印任何东西。我以某种方式错误地使用fread?
不要施加'malloc()'它是丑陋的和超级的。为什么'malloc()'这么庞大,只能使用'len'字节,这没有任何意义。它表明你的代码有错误,但你不在乎。 –
你忘记在'ftell'后倒回 –
实际上我们被告知假设输入文件为500MB。 – user1869558