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;
    }
}

猜你喜欢

转载自www.cnblogs.com/enomothem/p/12168640.html
今日推荐