题目:输入abc123,输出abc.
指针
void del_digit(char *str) {
char *ep = str;
char *sp = str;
while (*sp) {
if (isdigit(*sp)) {
sp++;
} else {
*ep++ = *sp++;
}
}
*ep = '\0';
}
循环
void del_digit2(char str[]) {
int i = 0;
int j = 0;
while (str[i]) {
if (isdigit(str[i])) {
i++;
} else {
str[j++] = str[i++];
}
}
str[j] = '\0';
}
测试:
char del[128];
printf("输入删除的字符:");
scanf("%s",del);
del_digit(del);
printf("FlyElephant:删除之后的结果:%s\n",del);
char del2[128];
printf("输入删除的字符2:");
scanf("%s",del2);
del_digit2(del2);
printf("FlyElephant:删除之后的结果2:%s\n",del2);