C lang: s_gets optimize input foo.

Xx_Introduction

s_getsis 《C primer plus》 optimize input foo.

Ax_Propose

Clear the cache._

Bx_Code

char * s_gets(char * st, int n)
{
    char * ret_val;
    char * find;

    ret_val = fgets(st, n, stdin);
    if (ret_val)
    {
        find = strchr(st, '
');
        if (find)
        {
            *find = '';
        }else
        {
            while (getchar() != '
')
                continue;
        }
        return ret_val;
    }
}
原文地址:https://www.cnblogs.com/enomothem/p/12168640.html