Question: int main() { void rmchr(char[],char); // call the function rmchr char s1[] = abracadabra; // create string with character inside of strings char s2[] =
int main()
{
void rmchr(char[],char); // call the function rmchr
char s1[] = "abracadabra"; // create string with character inside of strings
char s2[] = "abracadabra";
char s3[] = "abracadabra";
char s4[] = "aaaa";
char s5[] = "aaaa";
printf("Before rmchr : %s ",s1); // print out the orginal characters
rmchr(s1,'a'); // remove character 'a'
printf("After rmchr : %s ",s1); // print out the string after changed
printf("Before rmchr : %s ",s2); // print out the orginal characters
rmchr(s2,'b'); // remove character 'b'
printf("After rmchr : %s ",s2); // print out the string after changed
printf("Before rmchr : %s ",s3); // print out the orginal characters
rmchr(s3,'n'); // remove character 'n'
printf("After rmchr : %s ",s3); // print out the string after changed
printf("Before rmchr : %s ",s4);
rmchr(s4,'a'); // remove character 'a'
printf("After rmchr : %s ",s4);
printf("Before rmchr : %s ",s5);
rmchr(s5,'n'); // remove character 'n'
printf("After rmchr : %s ",s5);
}
void rmchr(char *string,char a)
{
int i, j; // for i loop
for (i=0; string[i]!='\0'; i++) // loop till 0 chracter found untill end
{
if(string[i]==a) // check if character equal to string
{
for (j=i;string[j] !='\0';j++) // for j loop
{
string[j] = string[j+1]; // replaced the string
}
string[j] = '\0'; // assign to term char
i--; // decrease i by one
}
}
}
Please helpe me rewrite void rmchr function by using pointer .
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
