用C语言函数调用,尽量不用for循环

编写一个程序,计算一串字符中字母、空格、数字以及其他标识符的出现次数并输出,并将字母和数字按顺序存储到对应数据类型的数组中,且字母需要进行大小写转化,并输出。计算与输出要用函数调用形式。

img

#include <stdio.h>
#include <string.h>
    char lt[250];
    int num[250];
    int letters=0,space=0,digit=0,other=0;
    int j=0,t=0,n=0;
void f1(char c[])
{
    while (j<strlen(c)) 
    {
        if ((c[j] >= 'a'&&c[j] <= 'z') || (c[j] >= 'A'&&c[j] <= 'Z')) 
        {
            letters++;
            if(c[j]<='z'&&c[j]>='a')
            lt[t++]=c[j]-32;
            if(c[j]<='Z'&&c[j]>='A')
            lt[t++]=c[j]+32;
        } else if (c[j] == ' ') {
            space++;
        } else if (c[j] >= '0'&&c[j] <= '9') {
            digit++;num[n++]=c[j]-48;
        } else {
            other++;
        }
        j++;
    }
}
void f2()
{
    j=0;
    printf("字母为:"); 
    while(j<t)
    {
        printf("%c",lt[j]);
        j++;
    }
    j=0;
    printf("\n数字为:"); 
    while(j<n)
    {
        printf("%d",num[j]);
        j++;
    }
    printf("\n");
}

int main() 
    {
    char c[250];
    printf("请输入一行字符:");
    gets(c);
    
    f1(c);
    printf("字母数:%d\n空格数:%d\n数字数:%d\n其他字符:%d\n",letters,space,digit,other);
    f2();
    
    return 0;
}