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

  • 相关阅读:
    2月11日
    亚特兰蒂斯
    080215 晴
    2月9日
    2月6日
    2月10日
    080208 晴(0,50)
    关于春晚
    (15,50)
    恍然大悟
  • 原文地址:https://www.cnblogs.com/jeanschen/p/3552232.html
Copyright © 2011-2022 走看看