Home > Back-end >  The C language
The C language

Time:11-02

Design an algorithm RepChar (s, x, y), all the character in the string s order to replace for the character y x, requirement for space complexity of O (1), and related data for testing, which bosses will teach me

CodePudding user response:

Whether to write a function to replace x of a character array to y
# # is for reference only
# include
# include
Void RepChar (char [] s, char x, char y)
{
for(int i=0; I{
If (s==x [I])
S [I]=y;
}
}
Int main ()
{
Char STR []="xycnbyxyx";
RepChar (STR, the 'x', 'y');
Printf (" % s \ n ", STR);
}
/* run results:
Yycnbyyyy
*/
  • Related