my_getline

int my_getline(char* line, int max_size)
{
    int c;
    int len = 0;

    //fflush(stdin);
    while( (c=getchar()) != '\n' && c != EOF);
    
    while( (c=getchar()) != EOF && len < max_size){
        line[len++]=c;
        if ('\n' == c)
        break;
    }

    line[len] ='\0';
    return len;
}

 

posted @ 2019-04-19 11:50  soul.stone  阅读(189)  评论(0编辑  收藏  举报