Question: In C: How to fix the code below so it remove the char from the original string not just print the other char. #include //Header

In C: How to fix the code below so it remove the char from the original string not just print the other char.

#include //Header Files

int main() { void rmchr(char[],char); //Function Declaration String,Character passing into function

char s1[]= "abracadabra"; //s1 to abracadabra char s2[]= "abracadabra"; //s2 to abracadabra char s3[]= "abracadabra"; //s3 to abracadabra char s4[]= "aaaa"; //s4 to aaaa char s5[]= "aaaa"; //s5 to aaaa printf("String\t\tCharacter\tAnswer "); printf("%s\t",s1); //Printing String Before Passing rmchr(s1,'a'); //Passing String and Character to remove into rmchr function

printf("%s\t",s2); //Printing String Before Passing rmchr(s2,'b'); //Passing String and Character to remove into rmchr function

printf("%s\t",s3); //Printing String Before Passing rmchr(s3,'n'); //Passing String and Character to remove into rmchr function

printf("%s\t\t",s4); //Printing String Before Passing rmchr(s4,'a'); //Passing String and Character to remove into rmchr function

printf("%s\t\t",s5); //Printing String Before Passing rmchr(s5,'n'); //Passing String and Character to remove into rmchr function

return 0; }

void rmchr(char str[],char ch) //Function Definition { char *p; //Pointer Variable p=&str[0]; //Storing address of First character of String in *p printf("%c\t\t",ch); //Printing Character to remove while(*p!='\0') //Loop for iterating String { if(*p!=ch) { //Checking if Character is not equal to each character printf("%c",*p); //Prints that unequal character } p++; //Address Increment of *p }

printf(" "); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!