#include <stdio.h> #include <string.h> int main() { char a[1000]; while (scanf("%999s", a) != EOF) { int len = strlen(a); char c; getchar(); /*新建一个数组接受处理后的结果 char b[1000]; scanf("%c", &c); int j = 0; int i = 0; while (i < len) { if (a[i] != c) { b[j] = a[i]; j++; } i++; } b[j]='\0'; printf("%s\n",b); */ //直接在原数组上进行操作 scanf("%c", &c); int j = 0; int i = 0; while (i < len) { if (a[i] != c) { a[j] = a[i]; j++; } i++; } a[j] = '\0'; printf("%s\n",a);//输出%s时以'\0'为结尾 } return 0; }