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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started