ungetc

功 能

  把一个字符退回到输入流中
 

编辑本段用 法

  int ungetc(char c, FILE *stream);

输入参数

  c 要写入的字符,stream 文件流指针

输出参数

  字符c - 操作成功,EOF - 操作失败
 

编辑本段程序例

  #include <stdio.h>
 
  #include <ctype.h>
 
  void main( void )
 
  {
 
  int ch;
 
  int result = 0;
 
  printf( "Enter an integer: " );
 
  /* Read in and convert number: */
 
  while( ((ch = getchar()) != EOF) && isdigit( ch ) )
 
  result = result * 10 + ch - '0'; /* Use digit. */
 
  if( ch != EOF )
 
  ungetc( ch, stdin ); /* Put nondigit back. */
 
  printf( "Number = %d\nNextcharacter in stream = %c",
 
  result, getchar() );
 
  }

Output

  Enter an integer: 521a
 
  Number = 521 Nextcharacter in stream = a
 

isdigit

 
  isdigit
 
  原型:extern int isdigit(char c);
 
  用法:#include <ctype.h>
 
  功能:判断字符c是否为数字
 
  说明:当c为数字0-9时,返回非零值,否则返回零。
 
  附加说明 此为宏定义,非真正函数。
 
  举例:
 
  // isdigit.c
 
  #include <syslib.h>
 
  #include <ctype.h>
 
  main()
 
  {
 
  int c;
 
  clrscr(); // clear screen
 
  c='a';
 
  printf("%c:%s\n",c,isdigit(c)?"yes":"no");
 
  c='9';
 
  printf("%c:%s\n",c,isdigit(c)?"yes":"no");
 
  c='*';
 
  printf("%c:%s\n",c,isdigit(c)?"yes":"no");
 
  getchar();
 
  return 0;
 
  }
 
  相关函数:isalnum,isalpha,isxdigit,iscntrl,isgraph,isprint,ispunct,isspace
 
 
 
原文地址:https://www.cnblogs.com/youxin/p/2275482.html