爲什麼此代碼的輸出是內存中的一些隨機字?從文件中獲取字符串
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