我提前道歉,因为我刚开始学习 C。这是我到目前为止的代码。
int main ()
{
char buf [4];
// open the file
FILE *fp = fopen("readme","r");
// Return if could not open file
if (fp == NULL)
return 0;
while(fgets(buf,4,fp) != NULL){
// Checking for end of file
if (feof(fp))
break ;
fputs(buf,stdout);
} while(1);
fclose(fp);
return(0);
}
我无法获得所需的结果。我假设将缓冲区设置为 4 可能会返回每行的前四个字符。我可能是错的,但我已经坚持了几个小时试图弄清楚如何溢出缓冲区。感谢任何帮助,谢谢!