栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言 输入一个长度小于80的字符串,将字符串中的字母字符滤掉掉,并统计新生成串中包含的字符个数。

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言 输入一个长度小于80的字符串,将字符串中的字母字符滤掉掉,并统计新生成串中包含的字符个数。

C语言实现:输入一个长度小于80的字符串,修改此字符串,将字符串中的字母字符滤掉掉,并统计新生成串中包含的字符个数。主函数如下,请实现函数fun。

主函数代码:

#include 

int main(void)
{
    char str[100];
    int s;
    printf("input a string:");
    gets(str);
    printf("The original string is :"); 
    puts(str);
    s = fun(str);
    printf("The new string is :");
    puts(str);
    printf("There are %d char in the new string.n",s);

    return 0;
}

全部代码实现如下:

#include 
#include
int fun(char p[])
{
    int a = 0, b = 0;
    char q[100];
    while (p[a] != '')
    {
        if ((p[a] >= 65 && p[a] <= 90) || (p[a] >= 97 && p[a] <= 122))  //根据ASCII码判断
            a++;
        else
        {
            q[b] = p[a];
            b++;
            a++;
        }
    }
    q[b] = '';
    strcpy(p, q);
    int len = strlen(p);
    return len;
}

int main(void)
{
    char str[100];
    int s;
    printf("input a string:");
    gets(str);
    printf("The original string is :");
    puts(str);
    s = fun(str);
    printf("The new string is :");
    puts(str);
    printf("There are %d char in the new string.n", s);

    return 0;
}

运行结果效果如下:

input a string:xiaoyuan123
The original string is :xiaoyuan123
The new string is :123
There are 3 char in the new string.

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/938451.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号