qq_36267626 2017-01-04 05:53 采纳率: 100%
浏览 1063
已采纳

考试题请大神帮忙写一下

从键盘输入字符串,字符串中含大写字母,小写字母,以及其他字符。编写程序将大写字母,小写字母,其他字符按顺序分离并分别保存在3个字符数组中,原字符数组保持不变。要求:(1)用3个子函数分别实现写字母,小写字母,其他字符的分离(2)子函数形式参数为指向性字符的指针变量(3)主函数中调用三个子函数实现各个字符的分离并显示原字符及3类分离后的字符。具体参照图片。图片说明

  • 写回答

5条回答

  • 码上见真晓 2017-01-04 09:18
    关注

    没什么难度,好心点给你代码吧
    #include
    #include

    void AtoZ(const char *p)
    {
    int i = 0;
    char q[50] = {0};
    while(*p != '\0')
    {
    if (*p >= 'A' && *p <= 'Z')
    {
    q[i] = *p;
    i++;
    }
    p++;
    }
    q[i] = '\0';
    printf("AtoZ: %s\n", q);
    return;
    }

    void atoz(const char *p)
    {
    int i = 0;
    char q[50] = {0};
    while(*p != '\0')
    {
    if (*p >= 'a' && *p <= 'z')
    {
    q[i] = *p;
    i++;
    }
    p++;
    }
    q[i] = '\0';
    printf("atoz: %s\n", q);
    return;
    }

    void other(const char *p)
    {
    int i = 0;
    char q[50] = {0};
    while(*p != '\0')
    {
    if (!(*p >= 'A' && *p <= 'Z')&&!(*p >= 'a' && *p <= 'z'))
    {
    q[i] = *p;
    i++;
    }
    p++;
    }
    q[i] = '\0';
    printf("other: %s\n", q);
    return;
    }

    int main(int argc, char const *argv[])
    {
    char str[50] = {0};

    printf("please input any string you want!\n");
    scanf("%s",str);
    getchar();
    char *p = str;
    
    //printf("cut out 'A' to 'Z'\n");
    AtoZ(p);
    //printf("cut out 'a' to 'z'\n");
    atoz(p);
    //printf("cut out the other\n");
    other(p);
    
    return 0;
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?