C Program to Delete a specific word From a String

Programming Example

C Program to input any string and remove the specified word from string 

Solution

#include<stdio.h>
#include<string.h>
int main()
{
    int i, j = 0, k = 0,n = 0;
    int flag = 0;
 
    char str[100], neww[100], word[100];

    printf("Enter Any String to Remove a Word from String: ");
    gets(str);
    printf("\n\n Enter Any Word You Want to be Removed: ");
    gets(word);
    for(i = 0 ; str[i] != '\0' ; i++)
    {
        k = i;
     
        while(str[i] == word[j])
        {
            i++,j++;
            if(j == strlen(word))
            {
                flag = 1;
                break;
            }
        }
    j = 0;
    if(flag == 0)
        i = k;      
    else
        flag = 0;

    neww[n++] = str[i];
    }
    neww[n] = '\0';    
    printf("\n\n After Removing Word From String: %s",neww);
	return 0;
}
Output

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Website development Company in Allahabad