词条 | cgets |
释义 | 函数简介函数名: cgets(在VC++6.0下为_cgets) 功 能: 从键盘得到一个字符串 用 法: char *_cgets( char *buffer ); 所属库:conio.h 相关函数:getch、getche、gets、getchar、_cgetws 程序示例#include <conio.h> #include <stdio.h> int main(void) { char buffer[83]; char *p; /* There's space for 80 characters plus the NULL terminator */ buffer[0] = 81; printf("Input some chars:"); p = cgets(buffer); printf("\cgets read %d characters: \\"%s\\"\", buffer[1], p); printf("The returned pointer is %p, buffer[0] is at %p\", p, &buffer); /* Leave room for 5 characters plus the NULL terminator */ buffer[0] = 6; printf("Input some chars:"); p = cgets(buffer); printf("\cgets read %d characters: \\"%s\\"\", buffer[1], p); printf("The returned pointer is %p, buffer[0] is at %p\", p, &buffer); return 0; } 下面的例子来自MSDN #include <conio.h> #include <stdio.h> #include <errno.h> int main( void ) { char buffer[83] = { 80 }; // Maximum characters in 1st byte char *result; printf( "Input line of text, followed by carriage return:\"); // Input a line of text: result = _cgets( buffer ); // C4996 // Note: _cgets is deprecated; consider using _cgets_s if (!result) { printf( "An error occurred reading from the console:" " error code %d\", errno); } else { printf( "\Line length = %d\Text = %s\", buffer[1], result ); } } |
随便看 |
百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。