PPS Practical 38

PPS Practical 38
  • Aim: Write a program to replace a character in given string.
  • Code:
    //For turbo C++ remove below comments
    #include <stdio.h>
    //#include<conio.h>
    void main()
    {
        char s[99],f,r;
        int i;
        //clrscr();
        printf("Enter string : ");
        gets(s);
        printf("Enter character to replace in string: ");
        f=getchar();
        getchar();
        printf("Enter character to replace %c in string : ",f);
        r=getchar();
        for (i = 0; s[i]!='\0' ; i++){
            if (s[i]==f){
                s[i]=r;
            }
        }
        printf("Resulted string : %s",s);
        // getch();
    }
  • Output: Output of practical 38

Comments