我好久没有编程了,随手编了一个,仅供参考
#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