zoukankan      html  css  js  c++  java
  • 实验 9 指针1 输入一行字符,要求用自定义的函数void f(char *line)统计和输出字符串中数字字符、英文字符和其他字符的个数

    #include<stdio.h>
    void f(char *line,int *a,int *b,int *c);
    int main(void)
    {
        int i=0,a,b,c;
        char ch,str[80];
        printf("Enter n:
    ");
        ch=getchar();          /*从键盘直接输入字符*/
        while(ch!='
    '){      
            str[i]=ch;
            i++;
            ch=getchar();
        }
        str[i]='';          /*结束标志*/
        f(str,&a,&b,&c);
        printf("Enter yingwen:%d
    Enter ch:%d
    other:%d
    ",a,b,c);
        return 0;
    }
    void f(char *line,int *a,int *b,int *c) /*定义自定义函数*/
    {
        *a=0;                                /*指针变量abc开始为空指针*/
        *b=0;
        *c=0;
        while(*line!=''){         
        if((*line>='a'&&*line<='z')||(*line>='A'&&*line<='Z'))
            (*a)++;
        else if(*line>='0'&&*line<='9')
            (*b)++;
        else
            (*c)++;
        line++;         
        }
    }
  • 相关阅读:
    NOI2021 题解
    CF605E Intergalaxy Trips
    P4762 [CERC2014]Virus synthesis
    特征向量与特征值
    uoj
    NOI 2021
    [NOI2011] NOI 嘉年华 【DP】
    CF1264D(组合数)
    绝对不咕
    题解 SP11985 【GOT
  • 原文地址:https://www.cnblogs.com/blgl/p/3422569.html
Copyright © 2011-2022 走看看