c语言去除字符串str中所有非数字字符然后输出无输入,输出为61209

如题所述

#include <stdio.h>

#include <string.h>

int main(void)

{

//c语言去除字符串str中所有非数字字符然后输出无输入,输出为61209

char a[100];

char b[100];

printf("请输入一串字符:");

gets(a);

int i, j = 0;

for (i = 0; i < strlen(a); i++) {

if ('0' <= a[i] && a[i] <= '9') {

b[j] = a[i];

j++;

}

}

printf("字符中的数字字符是:");

puts(b);

}
温馨提示:答案为网友推荐,仅供参考