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
", ch1);

    return 0;
}
gets 使用案例
原文地址:https://www.cnblogs.com/xiangsikai/p/12373646.html