输入一个字符,如果此字符在已知的字符串中出现,则删除此字符,如删除成功就返回被删字符,否则返回'\0'。请改正程序中的错误,使它能得出正确的结果。
#include <string.h>
#include <stdio.h>
char sh(char *a, char x)
{
int i = 0, k;
char q;
while (a[i] != '\0') i++;
for (int j = 0; j < i; j++);
{
if (a[j] = x)
{
q = a[j];
for (k = j; k <= i; k++)
a[k] = a[k + 1];
return q;
}
}
return '\0';
}
main()
{
char a[6] = "seven", x, ch;
printf("The Original string is:");
puts(a);
printf("Enter x: ");
scanf("%d", &x);
ch = sh(a, x);
if (ch = '\0')
printf("%c not found!!!", x);
else
{
printf("The deleted charactor is :");
puts(x);
}
printf("\nThe Original string changes to :");
puts(a);
}