字符分类代码 在输入数据文本后 会自动计算文本中的数字 符号 字母

#include<stdio.h>
#include<ctype.h>
#define buf_size 100
int main(void)
{
    char buf[buf_size];
    int nletters = 0;
    int ndigits = 0;
    int npunct = 0;

    printf("enter a interesting string of less than %d characters:\n", buf_size);
    if (fgets(buf, sizeof(buf),stdin)==NULL)
    {
        printf("error reading string");
        return 1;
    }
    size_t i = 0;
    while (buf[i])
    {
        if (isalpha(buf[i]))
            ++nletters;
        else if (isdigit(buf[i]))
            ++ndigits;
        else if (ispunct(buf[i]))
            ++npunct;
        ++i;
    }
    printf("\nyour string contained %d letters,%d digits and %d puncuation characters.\n",nletters,ndigits,npunct);
    
    return 0;
}

#include<stdio.h>
#include<ctype.h>
#define buf_size 100             //先定义buf_size确定长度
int main(void)
{
    char buf[buf_size];
    int nletters = 0;
    int ndigits = 0;
    int npunct = 0;

    printf("enter a interesting string of less than %d characters:\n", buf_size);
    if (fgets(buf, sizeof(buf),stdin)==NULL)
    {
        printf("error reading string");
        return 1;
    }
    size_t i = 0;
    while (buf[i])
    {
        if (isalpha(buf[i]))
            ++nletters;
        else if (isdigit(buf[i]))
            ++ndigits;
        else if (ispunct(buf[i]))
            ++npunct;
        ++i;
    }
    printf("\nyour string contained %d letters,%d digits and %d puncuation characters.\n",nletters,ndigits,npunct);
    
    return 0;
}

还是chatgpt帮了我大忙啊,帮我纠错什么太棒了,但是同时感觉到这种简单基本的代码al可以在两秒之内生成,所以如果只会基本代码的话那么al完全可以取代,需要的只是少数顶尖的程序员,日常维护al就行了

  • 11
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值