C語言庫函數 char *gets(char *str) 從標準輸入中讀取一行,並將其存儲到由str指向的字符串。它時停止讀取換行符或文件結束時達成,以先到為準。
聲明
以下是gets() 函數的聲明。
char *gets(char *str)參數
str -- 這是存儲所在的C字符串的字符數組的指針。
返回值
這個函數返回 str 則為 成功,NULL錯誤或文件結束時發生,而冇有字符已讀。
例子
下麵的例子顯示的使用 gets() 函數。
#include <stdio.h>
int main()
{
char str[50];
printf("Enter a string : ");
gets(str);
printf("You entered: %s", str);
return(0);
}
讓我們編譯和運行上麵的程序,這將產生以下結果:
Enter a string : gitbook.net
You entered: gitbook.net