int ungetc(int c, FILE *fp);
示例
//Visual Studio中加上这句才可以使用scanf()
//否则只能使用scanf_s()
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//malloc()、free()
#include <stdlib.h>
#include <time.h>
#include <math.h>
//argc: 参数个数 argv[]: 参数数组
//int main(int argc, char **argv)
int main(int argc, char *argv[])
{
char ch;
while ((ch = getchar()) != '\n')
{
//当读到冒号时,向stdin流中写入叹号
if (ch == ':')
ungetc('!', stdin);
else
putchar(ch);
}
putchar('\n');
system("pause");
return 0;
}
运行测试