请计算包含在英文字母列里的英文单词的个数,制作出在画面上打印的程序。使用Strtok()函数

图片说明

输入字符串: i am a boy
单词数有4个

输入字符串:hong gil dong
单词数有3个

#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;

char ch[1010];


int main()
{
        int x = 0;
    printf("输入字符串:");
        scanf("%[^\n]", ch);
        char *t = strtok(ch, " ");
        while (t != NULL)
        {
            x++;
            t = strtok(NULL, " ");
        }           
        cout << "单词个数有" << x << "个";
        return 0;
}

https://ask.csdn.net/questions/1082387 这个问题如果解决,请采纳下,谢谢