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, '\n');
        if (find)
        {
            *find = '\0';
        }else
        {
            while (getchar() != '\n')
                continue;
        }
        return ret_val;
    }
}

你可能感兴趣的:(C lang: s_gets optimize input foo.)