词条 | fgetchar |
释义 | C语言函数 函数名: fgetchar 功 能: 从流中读取字符,赋给一个字符变量。出错返回EOF。 用 法: 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'\",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\", buffer );} Input Line one. Line two. Output Line one. Line two. |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。