-
Passing Arrays of Strings
I am trying to write a function that will return the list of family members given the family name.
I want to pass the family name as an input (char array) and I want to return two arrays of strings that will return family member “roles” and their names. For example, if I pass the argument “McCoys” it will return something like:
familyMemberRoles = {‘Dad’, ‘Mom’, ‘Son’, ‘Daughter’};
familyMemberNames = {‘John’, ‘Jane’, ‘James’, ‘Jill’};
Let’s say I will have a main function and a function ‘getFamilyMembers’. There is some data structure that the function getFamilyMembers will access to get the info for me. So something like this:
Code:
void getFamilyMemberNames (const char *familyName, char ** familyMemberRoles, char ** familyMemberNames)
{
// Get the data here to populate familyMemberRoles, and familyMemberNames
}
int main ()
{
char *familyMemberRoles[];
char *familyMemberNames[];
getFamilyMembers(“McCoys”, familyMemberRoles, familyMemberNames )
// Do something with the info received
return 0;
}
Here are my questions:
- How do I initialize the arrays familyMemberRoles and familyMemberNames in the main function if I don’t know what their size will be? For example, some family can have more than 2 children so how would I initialize this and pass it to a function? And how do I “resize” the arrays in the function getFamilyMembers?
- Am I passing the variables familyMemberRoles, and familyMemberNames by reference correctly or do I do this differently?
- What is the best way of checking if the family is not found and the two arrays familyMemberRoles, and familyMemberNames are NULL?
Sorry, these might be very fundamental questions but I am new to C++. I would appreciate any help!
Alisha
Similar Threads
-
By Gunsmith2112 in forum C++
Replies: 5
Last Post: 12-08-2008, 10:06 AM
-
By CS Student in forum C++
Replies: 3
Last Post: 04-18-2008, 11:37 PM
-
By marcellus in forum .NET
Replies: 0
Last Post: 11-23-2006, 08:08 AM
-
By prototype in forum C++
Replies: 3
Last Post: 11-08-2001, 08:21 PM
-
By kingNewbie in forum C++
Replies: 2
Last Post: 05-22-2001, 08:22 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|