【leetcode】字符串中的单词数

 

int countSegments(char * s){
    int count=0;
    char* tok;
    tok = strtok(s," ");
    while (tok)
    {
        count++;
        tok = strtok(NULL, " ");        
    }
    return count;
}

 

posted @ 2020-09-14 09:58  温暖了寂寞  阅读(149)  评论(0编辑  收藏  举报