Chinaunix首页 | 论坛 | 博客
  • 博客访问: 21854
  • 博文数量: 11
  • 博客积分: 1411
  • 博客等级: 上尉
  • 技术积分: 115
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-17 17:42
文章分类

全部博文(11)

文章存档

2008年(11)

我的朋友
最近访客

分类: C/C++

2008-09-21 16:58:11

函数名: ungetc
  功 能: 把一个字符退回到输入流中
  用 法: int ungetc(char c, FILE *stream);
  输入参数:c 要写入的字符,stream 文件流指针
  输出参数:字符c - 操作成功,EOF - 操作失败
  程序例:
  #include
    #include
  int main( void )
  {
      int i=0;
      char ch;
      puts("Input an integer followed by a char:");
      /* read chars until non digit or EOF */
      while((ch = getchar()) != EOF && isdigit(ch))
          i = 10 * i + ch - 48; /* convert ASCII into int value */
      /* if non digit char was read, push it back into input buffer */
      if (ch != EOF)
          ungetc(ch, stdin);
      printf("i = %d, next char in buffer = %c\n", i, getchar());
      return 0;
  }
阅读(578) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~