做个记录,该函数可获取字符串中的数字,有需要的伙伴可以参考使用,第一参数为字符串,第二参数为空的整形数组,执行后数字按照字符串中的先后顺序排列在整形数组中,代码如下所示:
//获取字符串中的数字
void GetInStrNum(char *a, int *b)
{
int len=strlen(a),i,j,count=0,wei[20],times=0;
uint8_t ctoi=0,befctoi=0;
for(i=0;i<len+1;i++)
{
if(a[i]>='0'&&a[i]<='9')
{
ctoi=1;
}
else
{
ctoi=0;
}
if(befctoi==0&&ctoi==1)//上升沿
{
wei[count]=a[i]-'0';
befctoi=1;
count++;
}
else if(befctoi==1&&ctoi==1)//高位
{
wei[count]=a[i]-'0';
count++;
}
else if(befctoi==1&&ctoi==0)//下降沿
{
for(j=0;j<count;j++)
{
b[times]+=wei[j]*pow(10,count-j-1);
}
times++;
befctoi=0;
count=0;
}
}
}