您好我试图从 C 字符串中删除一个字符,但输出似乎不正确。例如,如果。输入字符串=“Hello”指定要删除的字符=“l”我的输出是“HeXXo”。删除字符后,我似乎需要将值推入?
下面的代码:
#include <stdio.h>
#include <stdlib.h>
void squeeze(char str[], char c);
void main (){
char input[100];
char c;
printf("Enter string \n");
gets(input);
printf("Enter char \n");
scanf("%c", &c);
printf("char is %c \n", c);
squeeze(input , c );
getchar();
getchar();
getchar();
}
void squeeze(char str[], char c){
int count = 0, i = 0;
while (str[count] != '\0'){
count++;
}
printf("Count = %d \n", count);
for ( i = 0 ; i != count; i++){
if (str[i] == c){
printf("Found at str[%d] \n", i);
str[i] = "";
}
}
printf(" String is = %s", str);
}