将数字存储到新数组里,输出没结果

若输入的字符串为yy99word123ok55man,则99放在a[0]中,123放在a[1]中……。

img


#include<stdio.h>
int getdig(char *p,int *q)
{     
    int i=0;      
    for( ; *p!='\0';p++)                
        if(*p>='0'&& *p<='9')               
        {     
            *q=0;                         
            p++;                      
            while(*p!='\0'&&(*p>='0'&& *p<='9'))                            
                *q=*q*10 + *p-'0';                        
            i++;                       
            q++;      
        }              
        return i;             
}
 int main()
{      
    char str[100],*p=str;      
    int a[100],*q=a,count=0;       
    gets(p);       
    count=getdig(p,q);                    
    for(q=a;q<a+count; q++)             
        printf("%4d",*q);
}

#include <stdio.h>
int getdig(char *p, int *q)
{
    int i = 0;

    for (; *p != '\0'; p++)
    {
        if (*p >= '0' && *p <= '9')
        {
            *q = 0;
            // p++;
            while (*p != '\0' && (*p >= '0' && *p <= '9'))
            {
                *q = *q * 10 + *p - '0';
                p++;
            }
            i++;
            q++;
        }
    }
    return i;
}

int main()
{
    char str[100] = "yy99word123ok55man"; //, *p = str;
    int a[100], *q, count = 0;
    gets(str);
    count = getdig(str, a);
    for (q = a; q < a + count; q++)
        printf("%4d", *q);
}