In: Computer Science
Write a recursive Racket function "remove-char" that takes two string parameters, s and c, and evaluates to string s with all occurrences of c removed. The string c is guaranteed to be a length-1 string; in other words a single character string. For example (remove-char "abc" "b") should evaluate to "ac". Here is pseudocode that you could implement.
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
char s[100],c;
int main()
{
char removal(char*,char);
printf("\n Enter the string:");
gets(s);
printf("\n Enter the character you want to remove in s :");
scanf("%c",&c);
removal(s,c);
return 0;
}
char removal(char *s,char c)
{
int i,j,length;
length=strlen(s);
for(i=0;i<length;i++)
{
if(s[i]==c)
{
for(j=i;j<length;j++)
{
s[j]=s[j+1];
}
length--;
i--;
}
}
printf("\nfinal string after Removing all occurences of c from s is
%s :",s);
return 0;
}
Output:
Reference: