
#include
#include
char words[100][100];
int numWords;
void GetWord(char *str) {
int flag,i;
char tmpstr[100],*p;
strcpy(tmpstr,str);
p = strtok(tmpstr," ");
while(p != NULL) {
flag = 1;
for(i = 0; i < numWords; ++i) {
if(strcmp(words[i],p) == 0) {
flag = 0;
break;
}
}
if(flag) {
strcpy(words[numWords],p);
++numWords;
}
p = strtok(NULL," ");
}
}
int main(void) {
char str[100];
printf("input a string :");
while(gets(str)) {
numWords = 0;
GetWord(str);
printf("不同单词的数量:%d\n",numWords);
printf("input a string :");
}
return 0;
}