发布时间:2019-07-29 16:09:53
思路:1. 对整个字符串从下标0开始查找a, 若某个位置没找到,就找到下一个位置,继续找;
若找到了,将a字符后面位置的字符串覆盖到a的位置,
然后在从此处查找,重复上面的步骤。
按你的要求,供参考的程序如下:#include<stdio.h>#include<string.h>#define N 50int main(){ char s[N]; char d[N]; int i, j, l; printf("Enter a string:"); gets(s); l=strlen(s); for(i=0,j=0;i<l;i++) { if(s[i]=='a'||s[i]=='A') continue; d[j++] = s[i]; } d[j] = '\0'; strcpy(s,d); printf("String after deleting the a character:"); puts(s); return 0; }程序的运行结果如下: