cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : Beginners : looping in a phone dir
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programm...
Articles
Lounge
Jobs

-

question  looping in a phone dir

osprey (2)
I need to write a program that requests a first and last name, lower case only.
then compares the name to a file the contains multiple entries of:
lastname, first
address1
address2

lastname, first
address1
address2

I have created a function to request the first and last name.
I have opened a stream (in main) to read the phone dir for last name, first name. address1. address2.

I do not know how to loop the requested name against the phone dir names..

sample code:
1
2
3
4
5
6
7
8
9
10
getName(firstName, lastName);

input.open("phoneDir");
getline(input, phoneBkName);
getline(input, phoneBkAddress1);
getline(input, phoneBkAddress2);

int spacePos = phoneBkName.find(' ');
phoneBkLast = phoneBkName.substr(0, spacePos-1);
phoneBkFirst = phoneBkName.substr(spacePos+1, 100);

//How to construct a loop to compare the requested name with the phoneDir name?

-Thank you
|
psault (88)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
getName(firstName, lastName);

input.open("phoneDir");

while (firstName!=phoneBkFirst && lastName!=phoneBkLast)
{

getline(input, phoneBkName);
getline(input, phoneBkAddress1);
getline(input, phoneBkAddress2);

int spacePos = phoneBkName.find(' ');
phoneBkLast = phoneBkName.substr(0, spacePos-1);
phoneBkFirst = phoneBkName.substr(spacePos+1, 100);

}
|

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2009 - All rights reserved - v2.2
Spotted an error? contact us