I have an array full of * characters. I need to replace any character from the array for another character that the user enters. Is it possible? I'll appreciate any suggestions. Thanks
#include <stdio.h>
#include <string.h>
strreplace(char[],char,char);
int main()
{
char s[17]="* * * *\n* * * * ";
char chr,repl_chr;
printf("%s", s);
printf("\nEnter character to be replaced: ");
chr=getchar();
fflush(stdin);
printf("\nEnter replacement character: ");
repl_chr=getchar();
printf("\nModified string after replacement is: \n");
strreplace(s,chr,repl_chr);
getch();
return 0;
}
strreplace(char s[], char chr, char repl_chr)
{
int i=0;
while(s[i]!=' ')
{
if(s[i]==chr)
{
s[i]=repl_chr;
}
i++;
}
puts(s);
return 0;
}