发布网友 发布时间:2022-04-20 08:01
共2个回答
热心网友 时间:2023-06-07 21:43
灞曞紑鍏ㄩ儴#include <stdio.h>
#include <ctype.h>
int GetWordNum(char str[])
{int i,n=0;
for(i=0;str[i];)
{while(!isalpha(str[i]))i++;
while(isalpha(str[i]))i++;
n++;
}
return n;
}
int main()
{ char s[300];
gets(s);
printf("%d\n",GetWordNum(s));
return 0;
}
热心网友 时间:2023-06-07 21:43
灞曞紑鍏ㄩ儴#include <stdio.h>
int GetWordNum(char str[]) {
int num = 0, word = 0;
char *p = str;
while (*p != '\n') {
if (*p == ' ')
word = 0;
else if (word == 0) {
word = 1;
num++;
}
p++;
}
return num;
}
int main(void) {
char str[10000];
fgets(str, 10000, stdin);
printf("%d\n", GetWordNum(str));
return 0;
}
杩介棶瀛愬嚱鏁板憿锛?p>杩界瓟鏀逛簡