Sunday, 20 March 2016

C Program to Delete Words from Sentence

Problem:- C Program to Delete Words from Sentence or C Program to Remove given Word from a String or C program to remove all occurrences of a word in string or C Program to Delete the Word in String or C program to remove the occurrence of the word from entered string or Write a C program to remove a specified word from a sentence or C program to Delete all occurrences of Character from the String or Delete a word from a string or C program to delete vowels from a string or C Program to Remove all Characters in a String Except Alphabet or C program to remove consecutive repeated characters from String or Delete particular word from string or c program to delete a substring from a string.

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Explanation:- Just like a searching an element in a sentence or in the string we have to perform the same operation for delete the particular word in a string or sentence. for that we have to first find the word is present in the string on sentence after that remove the word from the string or sentence. So first run a loop for main string and compare the string to substring, for each iteration increase the value of index if the substring is matched with the main string. then remove or if you want to print only the output so you can skip the character from main strings.

Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page.

Solution:-

#include<stdio.h>
#include<string.h>

void main()
{
/*Visit - www.programmingwithbasics.com*/
   
    printf("=====================================");
    printf("\nVisit - www.programmingwithbasics.com");
    printf("\n=====================================");
    
    int i, j = 0, k = 0,n = 0;
    int flag = 0;
 
    char str[100], new[100], word[100];

    printf("\n\nEnter Any String: ");
    gets(str);

    printf("\n\nEnter 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;

    new[n++] = str[i];
    }

    new[n] = '\0';
    
    printf("\n\nAfter Removing Word From String: %s\n",new);
}

Output:-

C Program to Delete Words from Sentence

You May Also See


1. C Program For Checking You Are Eligible For Voting Or Not

2. C Program For Finding Greater Between Two Number

3. C Program For Checking Number Is Even Or Odd

4. C Program For Check Leap Year Or Not Using If /Else Statement

5. C Program For Check Character Is Vowel Or Not Using If Else Statement

6. C++ Program To Find Quotient And Reminder Of Two Numbers Using If/Else Statements

7. C++ Program To Convert A Lowercase Alphabet To Uppercase Alphabet Or Vice-Versa Using If/Else Statements

8. C++ Program To Find Max Number Among Given Three Number Using If/Else Statements

9. C++ Program To Check Year Is Leap Year Or Not Using If/Else Statements

10. C++ Program To Find The HCF Or LCM Of Two Number Using If/Else Statements

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment