Hola,
Just like to say hi to everyone, i just joined the forums.
Ok, I have been playing with C++ now for about 3 or 4 months and have now hit a brick wall and need your help.
I am trying to write a program that will read in data from an input text file in the form of names and birthdates. After the data has been read in, the user willl be prompted to enter the month in which a person was born. After the user inputs the requested data, the program should output all persons in the text file with this birth month.
This is the input text file:
Snow White 2/26/1971 Peter Pan 10/1/1922 Miss Piggy 12/25/1966 Tish TheDish 3/22/1910 Mark Twain 11/11/1924 Poopsie Mugglesworth 4/10/1999 Lilly BenYoda 10/10/2003 Oscar deLaCruz 8/15/2003 Felix deLaCruz 8/15/2003 Espy deGuadelupe 5/13/2002 Amanda Jane 6/9/2004 Louise Allen 1/10/1960 Ida Red 7/4/1961
What i have been trying:
#include <iostream> #include <iomanip> #include <fstream> #include <conio> #include <cstring> using namespace std; struct B_Days { string names[2]; }; ifstream fin; ofstream fout; #define AND && #define OR || #define NOT != void headerfn( ); void inputfn(B_Days friends[51], int &count); int main( ) { headerfn( ); int count; B_Days friends[51]; char filename[51]; cout<<"Please enter the name and path of the input text file: "; cin>>filename; cout<<endl<<"Thank you! You entered: "<<filename<<endl<<endl; fin.open(filename); if(!fin) { cout<<"Input error\n\n" <<"Could not open text file\n\n" <<"Press any key to end\n\n"<<endl; getch( ); return 1; } inputfn(friends, count); cout<<"Please press any key to exit the program"<<endl; getch( ); return 0; } void headerfn( ) { cout<<setfill('*')<<setw(70)<<'*'<<endl<<endl; cout<<setw(5)<<' '<<"Electronic Address Book: This program reads names" <<" and birthdays from"<<endl; cout<<setw(5)<<' '<<"an input text file into an array of structs" <<" then outputs the names"<<endl; cout<<setw(5)<<' '<<"and birthdays of those born in the month of your" <<" choice."<<endl; cout<<setfill('*')<<setw(70)<<'*'<<endl<<endl; } void inputfn(B_Days friends[51], int &count) { count=0; while(!fin AND count < 51) { fin.get(friends[count].names, 20+1); count++; } }
Now, my question is: how do i go about reading this data in and then compare the birth month with the one entered? After i have compared the data, how do i return the result and output it? Do i use cstrings strcmp... or what?
Thanks,
:?: