You can use the following function:
char *chngChar (char *str, char oldChar, char newChar) {
char *strPtr = str;
while ((strPtr = strchr (strPtr, oldChar)) != NULL)
*strPtr++ = newChar;
return str;
}
It simply runs through a string that looks for a specific character and replaces it with a new character. Each time through (like yours) it starts with the address following the previous character, so as not to double-check the characters that have already been verified.
, , , :
printf ("%s\n", chngChar (myName, 'p', 'P'));