//将str中的数字提取出来
void digit(const char* str, int *a)
{
assert(str != NULL && a != NULL);
int tmp=0;
int i = 0;//a的下标
while (*str != '\0')
{
if (isdigit(*str))
{
tmp = tmp * 10 + *str - '0';
}
else if (tmp > 0)//检查是否有数据更新
{
a[i++] = tmp;
tmp = 0;
}
str++;
}
/*如果是123 ab45hh78的以数字字符结束的字符串,在上面的循环中是不能被存入数组a中,
所以要在结束循环后再检查一下tmp中是否有数据更新*/
if (tmp > 0)
{
a[i] = tmp;
}
}
提取字符串中的数字
最新推荐文章于 2020-11-18 14:18:21 发布