Click here to Skip to main content
15,867,957 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
file has 1000 lines that look like these

114680858 19670607 Matilda Vincent MI

114930037 19471024 Desdemona Hanover ID

115550206 19790110 Xanadu Perlman ND

116520629 19630921 Alexander Hall SD

117050976 19301016 David Lamprey GA

119610646 19650202 Thomas Porlock IL

120330928 19621126 Cary Cartman NC




struct employees
{
int ss_number;//social security
int dob;//date of birth YYYY/MM/DD Ex.) 19870314=1987/03/14
string f_name;
string l_name;
string state; //state of residence

};

void read_file()//read file into array of 1000 structs
{
ifstream data("/home/www/class/een118/labs/database1.txt");
employees array[1000]
if(!data.fail())
{
int i;
for(int i=0;i<1000;i++)
{
data>>array[i].ss_number
>>array[i].dob
>>array[i].f_name
>>array[i].l_name
>>array[i].state;
}
for(int i=0;i<1000;i++)
{
cout<<array[i].ss_number>>" "<<array[i].dob>>" "<<array[i].f_name>>" "<<
array[i].l_name>>" "<<array[i].state;
}
}
}
void print_person(employees e)
{
cout<<e.ss_number>>" "<<e.dob>>" "<<e.f_name>>" "<<e.l_name>>" "<<e.state;
}

void search(employees array[])//type in name and get that persons ss_number,dob etc...
{
string first;
string last;
cout<<"Enter name";
cin>>first>>last;
for(int i=0;i<1000;i++)
{
if(array[i].f_name==first && array[i].l_name==last)
{
print_person(array[i]);
}
}
}

void main()
{
employees array[10];
read_file();
search(array);
}s
Posted
Updated 17-Apr-14 13:15pm
v4
Comments
Sergey Alexandrovich Kryukov 17-Apr-14 19:10pm    
Platform? Language? What's the problem?
—SA
dudicus1414 17-Apr-14 19:12pm    
im in Unix using C++, when i type in a name, nothing appears.
[no name] 17-Apr-14 19:30pm    
Well off hand, I would say that there is probably nothing in your array. Study variable scope some more and learn how to use a debugger.
NeverJustHere 17-Apr-14 19:27pm    
I hope that is not real data you posted :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900