统计字符串中整数个数

//输入一个字符串,内有数字和非数字字符,例如:
//jh2515da555adad22 dsd55252aa
//将其中连续数字作为一个整数,依次存放在,一组数a中,
//例如,2515放在a[0],555放在a[1],,,,,,
//统计有多少个整数,并输出这些数。

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

int count=0;//统计整数个数

int Findnumbers(const char *str,int *des)
{
assert(str!=NULL&&des!=NULL);
int n;
int i=0;
int tmp=0;//jh2515da555adad22 dsd55252aa
do//使用do while防止出现bug(最后一位是数字的情况)
{
if(isdigit(*str))//数字
{
n=(str)-‘0’;
tmp=tmp
10+n;
i=1;
}
else
{
if(i==1)
{
*des=tmp;
des++;
count++;
i=0;
tmp=0;
}
}
str++;
}while((*str)!=’\0’);

return count;

}

int main()
{
int n;
int i;
const char arr[]=“jh2515da555adad22 dsd55252

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值