s_gets函数的使用

来源:互联网 发布:图拉丁 淘宝 编辑:程序博客网 时间:2024/06/14 06:01

每次都无法独立写出来,醉啊~

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'); // look for newline
if (find)     // if the address is not NULL,
*find = '\0';       // place a null character there
else
while (getchar() != '\n')
continue;    // dispose of rest of line
}
return ret_val;
}

原创粉丝点击