#include #include void removeSubstr(char *string, char *sub){ char *match; int len = strlen(sub); while ((match = strstr(string, sub))){ *match = '\0'; strcat(string, match+len); } } int main(){ char string[100], word[100]; printf ("Enter the string: "); //user input a sentence fgets(string,100,stdin); printf ("Enter the word to be removed: "); //inputs the words to be removed gets(word); printf("The words after removing: "); removeSubstr(string, word); puts(string); return 0; }
c language, how to modify this code to add word count before and after the word removal. Thanks! the output picture is what the output should look like except the output does not work for word removal but the code below can only do word removal but not the word count. please help.
#include <stdio.h>
#include <string.h>
void removeSubstr(char *string, char *sub){
char *match;
int len = strlen(sub);
while ((match = strstr(string, sub))){
*match = '\0';
strcat(string, match+len);
}
}
int main(){
char string[100], word[100];
printf ("Enter the string: ");
//user input a sentence
fgets(string,100,stdin);
printf ("Enter the word to be removed: ");
//inputs the words to be removed
gets(word);
printf("The words after removing: ");
removeSubstr(string, word);
puts(string);
return 0;
}


Step by step
Solved in 2 steps with 1 images









