输入一串字符,统计单词个数,单词之间用空格隔开,请问大家用C语言怎么做?

[复制链接]
查看11 | 回复2 | 2006-4-11 13:31:56 | 显示全部楼层 |阅读模式
main(){int j=0char p[] = "asd dsd dd";for(int i=0;p!=0;i++)if(p==0x20) j++;printf("nums:%d",j); }以上代码不处理连续空格, 需要扩展
回复

使用道具 举报

千问 | 2006-4-11 13:31:56 | 显示全部楼层
#include main(){ char string[81]; int i,num=0,word=0; char c; gets(string); for(i=0;(c=string)!='/0';i++) if(c==' ')word=0; else if(word==0) {word=1; num++;} printf("there are %d words in the line.\n",num);}
回复

使用道具 举报

千问 | 2006-4-11 13:31:56 | 显示全部楼层
书上有
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行