#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//去除字符串中的无效0
char* delete_zero(char* s)
{
char *p = s;
char a[100] = {0};//定义数组a,把处理后的字符串放进a中
char *q = a;
while(*p)
{
while(*p == '0')//一开始的0无效
{
p++;
}
while(*p >= '0' && *p <= '9')//如果是数字进入循环判断
{
if(*p == '0' && (*(p-1)<'0'||*(p-1)>'9'))//'0'左边不是数字,说明该0以及后面的0无效
{
while(*p == '0')//无效0,跳过
{
p++;
}
}
else
{
*q = *p;
q++;
p++;
}
}
*q = *p;
q++;
p++;
}
//输出去除无效0后的字符串
int n = strlen(a);
for(int i = 0; i < n; i++)
{
printf("%c",a[i]);
}
}
int main()
{
char* x = "00ab1200000cd000s012ef003400s700";//输出ab1200cds12ef3400s700
delete_zero(x);
return 0;
}