Go Back   Zune Boards > Help Forum > Tech. help

Tech. help Come here for help with technology related problems.

Closed Thread
 
LinkBack Thread Tools
Old 12-02-2008, 11:09 AM   #1 (permalink)
Super Zuner²
 
ChurchedAtheist's Avatar
 
Join Date: Nov 2006
Posts: 3,579
ChurchedAtheist is a name known to allChurchedAtheist is a name known to allChurchedAtheist is a name known to allChurchedAtheist is a name known to allChurchedAtheist is a name known to all
Default c++

ok, this is programing help, but afaik we don't have a programing section

I am stuck on a particular function of a program I am working on.

"void searchRecords()
This void function should prompt the user for search text, then open C:\PhoneBook.txt for input, read all records in the file,
and display all lines that contain the search text. Display a count of the records that matched the search text. Display a
different message if zero, one, or more matches are found."

an example line in phonebook.txt would be

allen 407566432

any ideas? I know I need to use string.find function to do it, just not sure how.
__________________

Quote:
Originally Posted by Marcus Aurelius
Live a good life. If there are gods and they are just, then they will not care how devout you have been, but will welcome you based on the virtues you have lived by. If there are gods, but unjust, then you should not want to worship them. If there are no gods, then you will be gone, but will have lived a noble life that will live on in the memories of your loved ones.




ChurchedAtheist is offline  

Advertisement [Remove Advertisement]
Old 12-02-2008, 11:18 AM   #2 (permalink)
Zune Priest
 
Azu-nyan's Avatar
 
Join Date: May 2008
Location: Planet Bob
Posts: 7,087
Azu-nyan is a jewel in the roughAzu-nyan is a jewel in the rough
Send a message via MSN to Azu-nyan Send a message via Skype™ to Azu-nyan
Default

You can always stuff it here: http://www.zuneboards.com/forums/dev...scussions-172/

Gimme a sec here, I think I have something like it somewhere....
__________________

o/ lolBeatrice \o
Quote:
Originally Posted by #sos-dan
21:42 <Azu-nyan>: And no, no happying. <.<
21:42 <Azu-nyan>: fapping*
21:42 <vonPreussen>: Freudian typos xD



Azu-nyan is offline  
Old 12-02-2008, 11:47 AM   #3 (permalink)
Super Zuner²
 
ChurchedAtheist's Avatar
 
Join Date: Nov 2006
Posts: 3,579
ChurchedAtheist is a name known to allChurchedAtheist is a name known to allChurchedAtheist is a name known to allChurchedAtheist is a name known to allChurchedAtheist is a name known to all
Default

does this look right?

void searchrecords()
{
ifstream indata;
string rec, line1;
int match;

cout << "Please enter the item to search for: ";

cin >> rec;

indata.open("phonebook.txt");

while (!indata.eof())
{
getline(indata, line1);

if (line1.find(rec) != string ::npos)
{
match++;
cout << line1 << endl;
}
}

if(match == 0)
cout << "0 matches found." << endl;

if(match == 1)
cout << "1 match found." << endl;

if(match >= 1)

cout << match << " matches found." << endl;

indata.close("phonebook.txt");

}
__________________

Quote:
Originally Posted by Marcus Aurelius
Live a good life. If there are gods and they are just, then they will not care how devout you have been, but will welcome you based on the virtues you have lived by. If there are gods, but unjust, then you should not want to worship them. If there are no gods, then you will be gone, but will have lived a noble life that will live on in the memories of your loved ones.

Last edited by ChurchedAtheist; 12-02-2008 at 11:59 AM.




ChurchedAtheist is offline  
Closed Thread

Bookmarks

Thread Tools