本质上,这是我的问题。
FILE *fp = "/my/textfile/location";
fseek(fp, 0L, SEEK_END);
int size = ftell(fp);
char *output_string[size];
printf("%d", size); // gives me 25
printf("%ld", sizeof(output_string)); // gives me 200.
为什么从ftell返回的int为20时,sizeof(output_string)给我200?
对不起我。
我不小心在数组声明中写了*,这使output_string成为一个指针数组,而不是chars
char *output_string[size];
这是指针数组,如果您在64位计算机上运行,一个指针是64位,即8个字节。如果大小为25,则:
sizeof(output_string) = 25 * sizeof(char *) = 25 * 8 = 200