代码改变世界

实验九用自定义的函数void f(char *line)统计和输出字符串中数字字符、英文字符和其他字符的个数。

2013-11-09 19:06  css1993  阅读(234)  评论(0编辑  收藏  举报
#include<stdio.h>
void f(char*line,int*digit,int*letter,int*other)
{
    *digit=*letter=*other=0;
    while(*line!='\0'){
        if(*line>='0'&&*line<='9')
            (*digit)++;
        else if((*line>='a'&&*line<='z')||(*line>='A'&&*line<='Z'))
            (*letter)++;
        else
            (*other)++;
        line++;
    }
}
int main()
{
    int i=0,digit,letter,other;
    char ch,line[100];
    printf("Enter charaters:");
    ch=getchar();
    while(ch!='\n'){
        line[i]=ch;
        ch=getchar();
    }
    line[i]='\0';
    f(line,&digit,&letter,&other);
    printf("digit=%d  letter=%d  other=%d\n",digit,letter,other);

    return 0;

}