Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to take input text from a user. Also take 2 words one that need to replace and one that will be replaced from sentence

Posted By: Krystal Spencer     Category: C Programming     Views: 3391

Program to take input text from a user. Also take 2 words one that need to replace and one that will be replaced from sentence

Code for Program to take input text from a user. Also take 2 words one that need to replace and one that will be replaced from sentence in C Programming

#include <stdio.h>
#include <conio.h>
    void main()
    {
        char a[100],b[10],t[20][20],c[10];
        int i=0,n=0,w=1,k=0;
        clrscr();
        printf("\n Enter The String : ");
        scanf("%[^\n]",a);
        printf("\n Enter The Word Need To Replace : ");
        scanf("%s",b);
        printf("\nEnter The New Word : ");
        scanf("%s",c);
        while(a[i]!='\0')
        {
            t[k][n]=a[i];
            if(a[i]==' ')
            {
                t[k][n]='\0';
                //printf("\n %s",t);
                n=-1;
                k++;
             }
            i++;
            n++;
        }
        printf("\n the replaced string is  : \t");
        for(i=0;i<k+1;i++)
        {
            if(strcmp(t[i],b)==0)
                strcpy(t[i],c);
            printf(" %s ",t[i]);
        }
        getch();
    }

/*
******
OUTPUT
******


Enter The String : This is a sample program

Enter The Word Need To Replace : sample

Enter The New Word : demo

The replaced string is : This is a demo program
*/
  
Share: 



Krystal Spencer
Krystal Spencer author of Program to take input text from a user. Also take 2 words one that need to replace and one that will be replaced from sentence is from Chicago, United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!