输入一句英文 用C语言统计 单词的个数 这个程序我写出来了 可是怎么弄运行结果都是1 看了半天不知道为什么

[复制链接]
查看11 | 回复1 | 2011-4-14 11:31:28 | 显示全部楼层 |阅读模式
#include
void main() {
char *str, str1[200];
int i=0, sum=0, temp=0;
str = str1;
scanf("%s", str);
for(i=0; str1!='\0'; i++) {
if( (str1>=65)&&(str1=97)&&(str1
void main() {

char *str, str1[200];

int i=0, sum=0, temp=0;

str = str1;

scanf("%s", str);

for(i=0; str1!='\0'; i++) {

if( (str1>=65)&&(str1=97)&&(str1main(){ char string[81]; inti, num=0,word=0; char c; gets(string); for(i=0;(c=string)!='\0';i++) //确定没有到结束符{ if(c==' ')
//当c获得的字符为空
回复

使用道具 举报

千问 | 2011-4-14 11:31:28 | 显示全部楼层
++temp多次后没有将temp复原成你想要的1,所以sum就是1了把if(temp==1)改成if(temp!=0)就可以了或者直接把++temp改成temp=1;
回复

使用道具 举报

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

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行