代码为:
#include <stdio.h>
int main ()
{
FILE *fp;
int c;
char buffer [256];
fp = fopen("file.txt", "r");
if( fp == NULL )
{
perror("打开文件时发生错误");
return(-1);
}
while(!feof(fp))
{
c = getc (fp);
/* 把 ! 替换为 + */
if( c == '!' )
{
ungetc ('+', fp);
}
else
{
ungetc(c, fp);
}
fgets(buffer, 255, fp);
fputs(buffer, stdout);
}
return(0);
}
file.txt文件内容为:
this is runoob
!c standard library
!library functions and macros
输出为:
this is runoob
+c standard library
+library functions and macros
+library functions and macros <---为什么这一行会输出的?
--
FROM 111.197.234.*