Sunday, February 25, 2018

C program : That replaces the occurence of a given character (say c) in a primary string (say PS) with another string (say s).

Input:
The first line contains the primary string (PS)
The next line contains a character (c)
The next line contains a string (s)

Output:
Print the string PS with every occurence of c replaced by s.
 
 
 #include<stdio.h>
#include<string.h>

int main()
{
    char PS[1000],s[1000],ch;

    scanf("%s %c %s", PS,&ch,s);

    for(int i=0;i<strlen(PS);i++)
        {
            if(PS[i]==ch)
                {
                    for(int i=0;i<strlen(s);i++)
                        printf("%c",s[i]);
                }
            else
                printf("%c",PS[i]);
        }


    return 0;
}

Thanks
Happy Computing!

No comments:

Post a Comment

Derivatives stock list at NSE

Complete FNO stock list at NSE. ABB India Ltd ACC Ltd APL Apollo Tubes Ltd AU Small Finance Bank Ltd Aarti Industries Ltd Abbott India Ltd A...