1、
#include <stdio.h> void del_dit(char x[]) { int i = 0, j = 0; char tmp[129]; while(x[i]) { if((x[i] - '0') < 0 || (x[i] - '0') > 9) { tmp[j] = x[i]; j++; } i++; } while(i-- > 0) x[i] = '\0'; for(i = 0; i < j; i++) { x[i] = tmp[i]; } } int main(void) { char str[129]; printf("str: "); scanf("%s", str); del_dit(str); printf("delete digit result: %s\n", str); return 0; }
2、
#include <stdio.h> void del_dig(char x[]) { int i = 0; while(x[i]) { if(x[i] >= '0' && x[i] <= '9') printf(""); else putchar(x[i]); i++; } } int main(void) { char str[128]; printf("str: "); scanf("%s", str); del_dig(str); return 0; }
3、
#include <stdio.h> void del_dig(char x[]) { int i = 0; while(x[i]) { if(x[i] >= '0' && x[i] <= '9') i++; else { putchar(x[i]); i++; } } } int main(void) { char str[128]; printf("str: "); scanf("%s", str); del_dig(str); return 0; }