/*********************************************
* @brief 从标准输入读取一个字符串
* @param[out] str 保存读取到的字符串
* @param n 字符串的最大长度(含末尾的 0)
* @return 是(非负)否(EOF)成功
********************************************/
char* gets_s(char* str, rsize_t n);
!subtitle:说明
从标准输入流 stdin 中读取一个字符串,以换行符(\n)或文件末尾(EOF)作为结束。
读入数组的最后一个字符后会自动添加字符串结束标志('\0'),输入的换行符(\n)会被丢弃。
!subtitle:参数
str - 保存读取到的字符串
n - 字符串的最大长度,含字符串结束标志('\0')
!subtitle:返回值
返回参数 str 本身
失败时返回 NULL
#include <stdio.h>
int main(void)
{
char text[64];
gets_s(text, 64);
return 0;
}
C23 standard (ISO/IEC 9899:2024):
K.3.5.4.1 The gets_s function (p: TBD)
C17 standard (ISO/IEC 9899:2018):
K.3.5.4.1 The gets_s function (p: TBD)
C11 standard (ISO/IEC 9899:2011):
K.3.5.4.1 The gets_s function (p: 602-603)