用c语言编程,将英语长句分割成英语单词序列输出,并输出其单词数目

如题所述

#include "stdio.h"

int main()

{int i,n=0,st=1;

 char s[200];

 gets(s);

 for(i=0;s[i];i++)

if(s[i]>='A'&&s[i]<='Z'||s[i]>='a'&&s[i]<='z')

{

st=1;

printf("%c",s[i]);

}

else

{

if(st==1){printf("\n");n++;}

st=0;

}

 printf("\nTotal has %d words.\n",n);

 getch();

 return 0;

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-12-08
#include<stdio.h>
#include<string.h>
int main(void)
{
char shou[1000];
char show[1000][1000];
char *p = NULL;
char *q = NULL;
int i = 0;
int j;
printf("请输入字符串shou:");
gets(shou);
p = q = shou;
while(*p == ' ')
{
p++;
}
q = p;
while(p = strchr(p,' '))
{
strncpy(show[i],q,p-q);
show[i][p-q] = '\0';
while(*p == ' ')
{
p++;
}
q = p;
i ++;
}
if (p == NULL && *q != '\0')
{
strncpy(show[i],q,strlen(q));
show[i][strlen(q)] = '\0';
i++;
}
for(j = 0; j < i; j++)
{
puts(show[j]);
}
printf("单词的个数为%d个\n",j);

}