C program to replace first occurrence of a character in a string

Write a C program to replace first occurrence of a character with another character in a string. How to replace first occurrence of a character with another character in a string using loop in C programming. Logic to replace first occurrence of a character in given string.

Example

Input

Input string: I love programming.
Input character to replace: .
Input character to replace with: !

Enter any string: I love Codeforwin.
Enter character to replace: I
Enter character to replace 'I' with: !
String before replacing: I love Codeforwin.
String after replacing first 'I' with '!' : ! love Codeforwin.

About Pankaj

Pankaj Prakash is the founder, editor and blogger at Codeforwin. He loves to learn new techs and write programming articles especially for beginners. He works at Vasudhaika Software Sols. as a Software Design Engineer and manages Codeforwin. In short Pankaj is Web developer, Blogger, Learner, Tech and Music lover.