char *s_gets(char *st, int n)
{
char *ret_val;
char *find;
ret_val = fgets(st, n, stdin);
if (ret_val)
{
find = strchr(st, '\n');
if (find)
{
*find = '\0';
}
else
{
while (getchar() != '\n')
continue;
}
}
return ret_val;
}
能不能用简单的代码把这个函数的用法演示一下,然后讲解一下这个函数的作用
这函数的作用:在字串中查找某个字符,若存在则返回字串中的位置索引,不存在返回空指针,就是想找字串中的换行符
从标准输入中获取最多n-1个字符,若存在,把最后一个换行替换为字串结尾符'\0',若不存在输入换行符结束输入,返回没有换行结尾的字串。