zoukankan      html  css  js  c++  java
  • 从键盘读取一个字符串,将字符串中所有连续的数字转换为对应的整数存储 到一个整数数组中,最后将这些整数输出

    /*从键盘读取一个字符串,将字符串中所有连续的数字转换为对应的整数存储
    到一个整数数组中,最后将这些整数输出 */
    #include <stdio.h>
    int fun2(char *p)//将连续数字字符转换为整数
    {
        int x=0;
        while(*p && *p>='0' && *p<='9')
        {
            x=x*10+*p-'0';
            p++;
        }
        return x;
     } 
    int fun1(char *s,int *a)
    {
        int x,n;
        char *p;
        n=0;p=s;
        while(*p)
        {
            while(*p &&(*p<'0'||*p>'9'))p++;
            if(*p)
            {
                *(a+n)=fun2(p);
                n++;
            }
            while(*p>='0' && *p<='9')p++;
        }
        return n;
    }
    int main()
    {
        char s[100];
        int a[10],i,n;
        gets(s);
        n=fun1(s,a);
        for(i=0;i<n;i++)
            printf("%d  ",a[i]);
        return 0;
    }

    运行结果:

  • 相关阅读:
    JAVA 练习1
    JSP基础
    网络协议
    mysql基础
    python之高级
    powershell基础
    python之迭代器与遍历
    python之面向对象
    linux常用命令
    docker 安装 ElasticSearch:7.4.2
  • 原文地址:https://www.cnblogs.com/yanglike111/p/13186285.html
Copyright © 2011-2022 走看看