为什么此代码的输出是内存中的一些随机字?从文件中获取字符串
void conc()
{
FILE *source = fopen("c.txt", "r+");
if(!source)
{
printf("Ficheiro não encontrado");
return;
}
short i = 0;
while(fgetc(source) != EOF)
i++;
char tmp_str[i];
fgets(tmp_str, i, source);
fclose(source);
printf("%s", tmp_str);
}
这应该给我的文件的内容,我认为。
你编译了你的应用程序吗? –
是你的'while'循环吗? – Bill