函數gets()
用於掃描來自用戶的字符串,沒有任何\n
或直到\n
性格。這個函數來自 string.h 類,執行與字符串相關的工作。
例:
gets(str) ; User input:"I AM A STRING" Output: I AM A STRING
你也可以使用scanf()
這比這個函數有更多的選擇。
stdio.h - C 中的 gets() 函數示例
#include <stdio.h>
int main()
{
//initializing the type of variables
char str[50];
char c;
//message for user
printf("Please enter a string:");
gets(str);
//printing the result
printf("Your String:%s\n\n", str);
//message for user
printf("Please enter a character:");
c = getchar();
//printing the result
printf("Your Character:");
putchar(c);
return (0);
}
輸出

相關用法
- C語言 getarcoords()用法及代碼示例
- C語言 getchar()用法及代碼示例
- C語言 getc()用法及代碼示例
- C語言 getpixel()用法及代碼示例
- C語言 getx()用法及代碼示例
- C語言 getch()用法及代碼示例
- C語言 getbkcolor()用法及代碼示例
- C語言 getdate()、setdate()用法及代碼示例
- C語言 getmaxx()用法及代碼示例
- C語言 gety()用法及代碼示例
- C語言 getmaxy()用法及代碼示例
- C語言 getmaxcolor()用法及代碼示例
- C語言 grapherrormsg()用法及代碼示例
- C語言 fread()用法及代碼示例
- C語言 feof()用法及代碼示例
- C語言 imagesize()用法及代碼示例
- C語言 strcspn()用法及代碼示例
- C語言 setlinestyle()用法及代碼示例
- C語言 showbits()用法及代碼示例
- C語言 sprintf()用法及代碼示例
注:本文由純淨天空篩選整理自Abhishek Sharma大神的英文原創作品 gets() function of stdio.h in C。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。