zoukankan      html  css  js  c++  java
  • ZT 输入一个字符串,查找它的第一个数字串,并返回其个数

    /*查找字符串中的数字串问题
    
     
    输入一个字符串,查找它的第一个数字串,并返回其个数
    */
    
    
    #include <stdio.h>
    
    char firstnum(char *input,char *output)
    {
        char *in=input,*out=output,*temp;
        int count=0,i;
        while(*in !='')
        {
            if(*in>='0'&&*in<='9')
            {
               count=0;
               for(temp=in;*in>='0'&&*in<='9';in++)
               {
                count++;
               }
               if((*in>='a' && *in<='z')|| *in>='A' && *in<='Z')
               {
                   break;
               }
            }
            in++;
        }
        for(i=0;i<count;i++)
        {
            *out++=*temp++;
        }
        *out='';
    
        return count;
    }
    int main(void)
    {
        char input[] = "7892356asdfghjk123456789";
        char output[1000] = {0};
        int count = firstnum(input,output);
        printf("the str %s
    ",output);
        printf("the count is %d 
    ",count);
    
        return 0;
    }
    /work/ctest/interview$ ./1
    the str 7892356
    the count is 7

  • 相关阅读:
    dubbo
    常见线程池
    面试之葵花宝典
    Java线程池
    DB2分页
    平凡
    自由职业一时爽,一直自由一直爽
    弱水三千,只取一瓢。
    没病到一定程度,你千万别去。
    一个转身一个轮回
  • 原文地址:https://www.cnblogs.com/jeanschen/p/3552232.html
Copyright © 2011-2022 走看看