| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 754 人关注过本帖
标题:[求助]怎么实现啊?
只看楼主 加入收藏
qxkjsha
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-2-25
收藏
 问题点数:0 回复次数:4 
[求助]怎么实现啊?
.输入一串字符,直到输入一个星号(*)为止,统计(输出)其中的字母个数和数字字符个数。
我写的好像不行
#include "stdio.h"
 int main()
{
   int i;
   int letter=0;
   int number=0;
   char s[200];
   puts("please inpute the the character");
   
   while (getchar()=='*')
   
   s[200]=getchar();
   while(s[200]==getchar()!='*')
     for(i=1;i<200;i++)
     if (s[i]>='a'||s[i]<='z'||s[i]>='A'|| s[i]<='Z')
           letter++;
        if (s[i]>='0'|| s[i]<='9')
   number++;
  printf("there are %d numbers,%d letters.\n", number,letter);
     return 0;
}
搜索更多相关主题的帖子: int getchar letter number 
2005-10-26 15:24
young
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:223
专家分:160
注 册:2004-9-5
收藏
得分:0 

我好久没有编程了,随手编了一个,仅供参考 #include "stdio.h" #include "conio.h" #include "ASSERT.H" #if 0 int main() { int i; int letter=0; int number=0; char s[200]; puts("please inpute the the character"); while (getchar()=='*') s[200]=getchar(); while(s[200]==getchar()!='*') for(i=1;i<200;i++) if (s[i]>='a'||s[i]<='z'||s[i]>='A'|| s[i]<='Z') letter++; if (s[i]>='0'|| s[i]<='9') number++; printf("there are %d numbers,%d letters.\n", number,letter); return 0; } #else void main(void) { char s[200]={0}; int i=0; int numCount=0, charCount=0;

fprintf(stdout, "please input the string:\n"); while((s[i]=getch())!='*') { fputchar(s[i]); i++; assert(i<sizeof(s)); }; i=0; while(*(s+i)) { if(*(s+i)>='0' && *(s+i)<='9') numCount++; else if((*(s+i)>='a' && *(s+i)<='z')||(*(s+i)>='A' && *(s+i)<='Z')) charCount++; else NULL; i++; } fprintf(stdout, "\nnumCount=%d---charCount=%d\n", numCount, charCount); } #endif


如果你爱C语言,请你爱指针; 如果你爱指针,请你爱指针的指针;
2005-10-26 17:12
wenyong
Rank: 1
等 级:新手上路
帖 子:251
专家分:0
注 册:2005-8-9
收藏
得分:0 
while (getchar()=='*')
   
   s[200]=getchar();
   while(s[200]==getchar()!='*')

三句都有错误!

2005-10-26 17:33
woshiyfk
Rank: 1
等 级:新手上路
帖 子:74
专家分:0
注 册:2005-3-2
收藏
得分:0 
while (getchar()=='*')
   
   s[200]=getchar();
   while(s[200]==getchar()!='*')

铁打的错了,getchar()是一个函数啊,循环判断的时候用过一次,再下面再用  原来的那个字符就被新的字符代替了,电脑根本就着找不着北,建议加一个变量,把while里面的getchar()保存起来用来判断

2005-10-27 09:20
qxkjsha
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-2-25
收藏
得分:0 
谁给写一个范例撒
2005-10-27 11:37
快速回复:[求助]怎么实现啊?
数据加载中...
 
   



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

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