查找字符串中的数字并返回其个数:
#include
int main(void)
{
char str;
int i, count, a;
int p, q, r;
int tmp;
gets(str);
r = 0;
count = 0;
while(1)
{
while(str[r] && (str[r]<'0' || str[r]>'9'))
r++; //跳过非数字
if(str[r])
{
p = r; //p指向数字子串开头
q = r + 1; //q寻找数字串结尾
a[count] = str[r]-'0';
while(str[q]>='0' && str[q]<='9')
{
a[count] = 10*a[count]+(str[q]-'0');
q++;
}
r = q; //新起点
count++;
}
else
break;
}
printf("共计 %d 个整数:", count);
for(i=0; i
printf("%d ", a[i]);
printf("
");
return 0;
}
标签:www,moe,gov