我写的好像不行
#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;
}
----------------解决方案--------------------------------------------------------
我好久没有编程了,随手编了一个,仅供参考 #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
----------------解决方案--------------------------------------------------------
while (getchar()=='*')
s[200]=getchar();
while(s[200]==getchar()!='*')
三句都有错误!
----------------解决方案--------------------------------------------------------
while (getchar()=='*')
s[200]=getchar();
while(s[200]==getchar()!='*')
铁打的错了,getchar()是一个函数啊,循环判断的时候用过一次,再下面再用 原来的那个字符就被新的字符代替了,电脑根本就着找不着北,建议加一个变量,把while里面的getchar()保存起来用来判断
----------------解决方案--------------------------------------------------------
谁给写一个范例撒
----------------解决方案--------------------------------------------------------