Mister-小方


私信TA

用户名:1104986125

访问量:238717

签 名:

如此英俊为哪般

等  级
排  名 3
经  验 35675
参赛次数 1
文章发表 68
年  龄 19
在职情况 学生
学  校 大连交通大学
专  业 车辆工程

  自我简介:

TA的其他文章

解题思路以及注意事项:

  1. 由于需要接收空格字符,所以建议使用gets()函数,scanf()函数接收到空格就结束了,所以不建议使用scanf.

  2. 注意初始化的问题。

实例代码:

#include"stdio.h"
int main()
{
    int i,word=0,number=0,space=0,others=0,zero=0,sum=0;
    char words[100];
    gets(words);
    for(i=0;i<100;i++){                      //计算用户输入了多少个字符
        if(words[i]=='\0')                   //遇到结束标志就结束循环
        {
            break;
        }
        sum++;
    }
    for(i=0;i<sum;i++){                      //依次遍历整个数组words
        if('a'<=words[i]&&words[i]<='z'||'A'<=words[i]&&words[i]<='Z')
        {
            word++;
        }
        else if('0'<=words[i]&&words[i]<='9')
        {
            number++;
            
        }
        else if(words[i]==' ')
        {
            space++;
            
        }
        else
        {
            others++;
        }
    }
    printf("%d\n%d\n%d\n%d",word,space,number,others);
    return 0;
}

看看还有什么不懂的,请在下方留言,如果自认为有比小方写的好的,小方期待你写出比我精彩的题解

 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区