Monday, September 3, 2018

Remove a Word From a String in C++

This is a very simple program that will ask the user to give a sentence and the program will remove the word in the given by the user in the sentence using C++.

I am currently accepting programming work, it project, school 

programming projects , thesis and capstone projects, IT consulting 

work, computer tutorials and web development work kindly contact me in the following email address for further details.  If you want to advertise in my website kindly contact me also in my email address also. Thank you.
My email address are the following jakerpomperada@gmail.com, jakerpomperada@aol.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

My personal website is http://www.jakerpomperada.com



Sample Program Output



Program Listing


// Author    : Mr. Jake R. Pomperada, BSCS,MAED-IT
// Date      : September 2, 2018   Sunday  9:58 PM
// Location  : Bacolod City, Negros Occidental Philippines.
// Website   : http://www.jakerpomperada.com
// Email     : jakerpomperada@jakerpomperada.com and jakerpomperada@gmail.com

#include <iostream>
#include <cstring>

using namespace std;
  
int main()
{
   char string[100], pattern[100];
   char *ptr;
   int length;
    
system("COLOR F0");  
cout << "\n\n";
    cout << "\tRemove a Word From a String";
    cout << "\n\n";
   cout << "\tEnter a string : ";
   cin.getline(string, 100);
   cout << "\n\n";
   cout << "\tEnter string to remove : ";
   cin.getline(pattern, 100);
   length = strlen(pattern);
   
   ptr = strstr(string, pattern);
      
   strcpy(ptr, ptr+length);
   cout << "\n\n";
   cout << "\tThe final result : " << string;
   cout << "\n\n";
   cout <<"\tEnd of Program";
   cout << "\n\n"; 
   return(0);
}


No comments:

Post a Comment