基本介紹
- 中文名:fgetchar
- 名詞類型:函式
- 名詞領域:編程
- 語言:C,C++
簡介,案例,
簡介
函式名: fgetchar
用 法: int fgetchar(void);
案例
程式例:
#include <stdio.h>int main(void){ char ch;/* prompt the user for input */ printf("Enter a character followed by \<Enter>: ");/* read the character from stdin */ ch = fgetchar();/* display what was read */ printf("The character read is: '%c'\n",ch); return 0;}
在Visual C + + 2005開始,這是推薦使用的POSIX函式。使用ISO C + +遵從的_fgetchar代替。
原文:This POSIX function is deprecated beginning in Visual C++ 2005. Use the ISO C++ conformant _fgetchar instead.
MSDN中例子:
// crt_fgetchar.c// This program uses _fgetchar to read the first// 80 input characters (or until the end of input)// and place them into a string named buffer.//#include <stdio.h>#include <stdlib.h>int main( void ){ char buffer[81]; int i, ch; // Read in first 80 characters and place them in "buffer": ch = _fgetchar(); for( i=0; (i < 80 ) && ( feof( stdin ) == 0 ); i++ ) { buffer[i] = (char)ch; ch = _fgetchar(); } // Add null to end string buffer[i] = '\0'; printf( "%s\n", buffer );}
Input
Line one.
Line two.
Output
Line one.
Line two.