C语言 gets

C语言 gets

#include <stdio.h>
char *gets(char *s);

功能:从标准输入读入字符,并保存到s指定的内存空间,直到出现换行符或读到文件结尾为止。

参数:

  • s:字符串首地址

返回值:

  • 成功:读入的字符串
  • 失败:NULL

案例

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

int main(void)
{

    // gets()
    // 通过键盘获取一个字符串
    // 接受字符串可以带空格
    char ch1[100];
    gets(ch1);
    printf("%s\n", ch1);

    return 0;
}
gets 使用案例

 

posted @ 2020-02-27 18:43  kevin.Xiang  阅读(511)  评论(0编辑  收藏  举报