#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; }

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 2RQ
icon
Related questions
Question

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;
}

make -s
> ./main
Enter the string:
To be or not to be that is the question
Enter the word to be removed:
that is the question
The words before removing: 10
String or sentence after removing: To be or not to be that is t
he question
The words after removing: 10
Transcribed Image Text:make -s > ./main Enter the string: To be or not to be that is the question Enter the word to be removed: that is the question The words before removing: 10 String or sentence after removing: To be or not to be that is t he question The words after removing: 10
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT