| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1193 人关注过本帖
标题:[求助]C语言改错
只看楼主 加入收藏
无玩过界
Rank: 1
等 级:新手上路
威 望:2
帖 子:246
专家分:0
注 册:2007-2-20
收藏
得分:0 
#include<stdio.h>
main()
{ int c;
int letter=0,digit=0,space=0,other=0;
printf("Please input a string:\n");
while ((c=getchar())!='\n')
if (c>='a'&&c<='z'||c>='A'&&c<='Z')
letter++;
else if (c>='0'&&c<='9')
digit++;
else if (c==' ')
space++;
else
other++;
printf("letter=%d, ",letter);
printf("digit=%d, ",digit);
printf("space=%d, ",space);
printf("other=%d\n",other);
}

2007-05-29 18:08
无玩过界
Rank: 1
等 级:新手上路
威 望:2
帖 子:246
专家分:0
注 册:2007-2-20
收藏
得分:0 
以下是引用魅炫浩子在2007-5-29 15:28:55的发言:

程序的功能是从键盘输入一行字符,
分别统计其中的字母、数字、空格和其它字符的个数。但该程序中有3处错误
include <stdio.h>漏了预处理符#
main()
{ int c;
int letter=0,digit=0,space=0,other=0;
printf("Please input a string:\n");
while (c=getchar()!='\n')
if (c>='a'&&c<='z'||c>='A'&&c<='Z')
letter++;
else if (c>='0'&&c<='9')
digit++;
else if (c=' ')注意是==,不是=,因为两者有分别,一个等于,另一个是赋值(即将自身值复制给别人)
space--;这里改为++,否则看结果为负数
else
other++;
printf("letter=%d, ",letter);
printf("digit=%d, ",digit);
printf("space=%d, ",space);
printf("other=%d\n",other);
}

帮我看看哪些是错的


2007-05-29 18:13
夜中梦
Rank: 1
等 级:新手上路
帖 子:132
专家分:0
注 册:2007-5-12
收藏
得分:0 
以下是引用魅炫浩子在2007-5-29 15:28:55的发言:

程序的功能是从键盘输入一行字符,
分别统计其中的字母、数字、空格和其它字符的个数。但该程序中有3处错误
#include <stdio.h>
main()
{ int c;
int letter=0,digit=0,space=0,other=0;
printf("Please input a string:\n");
while (c=getchar()!='\n')
if (c>='a'&&c<='z'||c>='A'&&c<='Z')
letter++;
else if (c>='0'&&c<='9')
digit++;
else if (c==' ')
space--;
else
other++;
printf("letter=%d, ",letter);
printf("digit=%d, ",digit);
printf("space=%d, ",space);
printf("other=%d\n",other);
}

帮我看看哪些是错的


2007-05-29 22:36
魅炫浩子
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2007-5-28
收藏
得分:0 
谢谢!

2007-06-06 20:41
快速回复:[求助]C语言改错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030170 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved