Advertisement



Go Back   Zune Boards > Help Forum > Tech. help

New Member?



 
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

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

Closed Thread
 
LinkBack Thread Tools
Old 12-02-2008, 11:09 AM   #1 (permalink)
n00blet chef
Jr. Staff
Expert Zuner
 
EndUnknown's Avatar
 
Join Date: Nov 2006
Posts: 3,200
Reputation: 379
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.



__________________
Come spark a debate in the Religion Forum

Quote:
Originally Posted by Locke
*Locke is a naughty boy
Quote:
Originally Posted by Locke View Post
*Locke is in yur publics, stalkin yur s3xxorz




EndUnknown is offline  
Old 12-02-2008, 11:18 AM   #2 (permalink)
Official Editor of the SB
Support Team
Moderator
Zune Lord
 
Locke's Avatar
 
Join Date: May 2008
Location: In the kitchen, preparing a brand new batch of n00blets
Posts: 5,209
Reputation: 960
Send a message via MSN to Locke
Awards Showcase
Biggest Shouter Spam King/Queen 
Total Awards: 5
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....
__________________

Quote:
Originally Posted by Pokeyourheadoff View Post
If you wish to have more people understand you please use grammar and spelling correctly. Commas are a wonderful invention. Use them. Please.




Locke is offline  
Old 12-02-2008, 11:47 AM   #3 (permalink)
n00blet chef
Jr. Staff
Expert Zuner
 
EndUnknown's Avatar
 
Join Date: Nov 2006
Posts: 3,200
Reputation: 379
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");

}
__________________
Come spark a debate in the Religion Forum

Quote:
Originally Posted by Locke
*Locke is a naughty boy
Quote:
Originally Posted by Locke View Post
*Locke is in yur publics, stalkin yur s3xxorz

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




EndUnknown is offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -8. The time now is 08:31 PM.

 
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0 RC8
vB Ad Management by =RedTyger=
(C) ZuneBoards 2006-2007
Copyright © 2006 - 2008 Zune Boards | About Zune Boards | Legal | A member of the Crowdgather Forum Community