Friday, August 16, 2019

Search a Name in the Text File in C++

Design a program using a text file that will allow the user to search a name of the person stored in a text file. If the name of the person found in the text file that program will inform the user that the name of the person is found. On the other hand, if the name of the person cannot be found in the text file, the program will inform the user that the name is not found.

I am currently accepting programming work, IT projects, school and application development, 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 on my website kindly contact me also in my email address also. Thank you.

My email address is 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.

Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.

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






Sample Program Output


Program Listing

// search.cpp
// Author   : Mr. Jake R. Pomperada,BSCS,MAED-IT
// Address  : Bacolod City, Negros Occidental Philippines
// Date     : September 6, 2018      Thursday   8:75 AM
// Website  : jakerpomperada.com
// Email    : jakerpomperada@jakerpomperada.com and jakerpomperada@aol.com
// Tool     : Dev C++ Version 5.11

#include <iostream>
#include <fstream>

using namespace std;

int search (char a[]) 
{
char *search = a ; 
int offset;
string line;
ifstream Myfile;
Myfile.open("demo.txt");
if(Myfile.is_open())
{
while(!Myfile.eof())
{
getline(Myfile,line);
if ((offset = line.find(search,0)) != string::npos) 
   {
 cout <<"\n\n";            
 cout << "\tThe name "<< search <<" is FOUND in the text file.";
 cout <<"\n\n";
 goto terminate;
  } 
}
cout <<"\n\n";    
cout << "\tThe name "<< search <<" is NOT FOUND in the text file.";
cout <<"\n\n";
Myfile.close();
}
else 
cout<<"Unable to open this file."<<endl;
terminate:
cout <<"\n";    
cout << "\tThank you for Using This Software.";
cout <<"\n\n";          
system("pause");
}

int main()
{
    char name[100];
    system("COLOR F0");
    cout <<"\n\n";
    cout <<"\tSearch a Name in the Text File in C++";
    cout <<"\n\n";
    cout<<"\tEnter name to search : ";
    fflush(stdin);
    cin.getline(name,50);
    search(name);
}



No comments:

Post a Comment