輸入一個(gè)字符,如果此字符在已知的字符串中出現(xiàn),則刪除此字符,如刪除成功就返回被刪字符,否則返回'\0'。請(qǐng)改正程序中的錯(cuò)誤,使它能得出正確的結(jié)果。#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);}
- 1 回答
- 0 關(guān)注
- 1387 瀏覽
添加回答
舉報(bào)
0/150
提交
取消