Dotcpp  >  编程教程  >  stdio.h头文件  >  C语言gets()函数:从输入流中取一字符串

C语言gets()函数:从输入流中取一字符串

点击打开在线编译器,边学边练

函数名: gets

头文件:<stdio.h>

函数原型: char *gets(char *str);

功 能: 从输入流中取一字符串

参 数: 将读取的字符串保存在str中

返回值: 成功   返回指向str的字符串指针 ,遇到EOF或发生错误   返回NULL指针


程序例:  在控制台获取字符串,并输出字符串

#include<stdio.h>

int main(void){

   char str[80];

   printf("Input a str:");

   gets(str);

   printf("The string input was: %s\n", str);

   return 0;

}

 

运行结果

Input a str:www.dotcpp.com
The string input was: www.dotcpp.com



本文固定URL:https://www.dotcpp.com/course/521

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)