Hi,
So I'm having a problem getting information from a vector I've created.
The vector is composed of a class I've called "person". When I try to get the first name of the person I usually get garbage text i.e some weird text I can't type.
I believe the problem is the transfer of the name between the classes, but I'm not sure.
The flow of the program goes as such:
Choice getting (in main.cpp)
1 2 3 4
|
else if (decision == 3)
{
MyDecisionProcessor.FIND();
}
|
Getting the ID of the person (in decisionProcessor.cpp)
1 2 3 4 5 6
|
printf("Insert the member ID of the person you want to find : ");
fgets(choice, MAX_INPUT, stdin);
sscanf(choice, "%d", &MemberID);
MyDatabase.find(MemberID);
|
Here is the outputting/finding function (in database.h)
1 2 3 4 5 6 7 8 9
|
vector<Person>::iterator i;
for (i = DBase.begin(); i != DBase.end(); ++i)
{
if (i->getID() == ID)
{
printf("The name is %s", i->getFirst());
}
}
|
Now, I've stepped through and I get into the IF of the above loop, so I know that
does function as it should. "The name is " also prints out, but I get 3 weird characters even if the name was longer.
and here is the get name function (in person.h)
1 2 3 4
|
string getFirst (void)
{
return FirstName;
}
|
ANY help is appreciated, if you need to see any more of the code just ask.