From file to arrays.

Write your question here.




Hello everyone, I am trying to get information from a file into arrays. The text file goes something like this:
John Doe 8087793254 021489
Jane Plain 8087746587 120286
Larry Red 8746589874 022565

and so on.
I want to put the first names in an array for first names, the last names in an array for last names and the numbers in each of their own arrays and i need help putting them in the arrays.
Thanks for the help
Your request is not specific . Please show us what you have tried, then tell us where you are stuck ! peace.
unsigned short DisplayInfo(char fname[][size], char lname[][size], int phone[11], int birth[7])
{
unsigned short num = 0;
ifstream info("Information.txt");
if (info)
{
info >> fname[num] >> lname[num] >> phone[num] >> birth[num];
while (!info.eof())
{
num++;
info >> fname[num] >> lname[num] >> phone[num] >> birth[num];
}//end while
info.close();
}
else
{
cout << "\nerror";
}


Here is what is got; i pull the information into the arrays and i want to display it, but i am not sure if it is working or how to display them.

what are you trying to do here ? why are you passing a multidimensional arrays of char ?
unsigned short DisplayInfo(char fname[][size], char lname[][size], int phone[11], int birth[7])
i changed the function to a void and and got rid of the other arrays on char fname and lname so its :

void DisplayInfo( char fname[size], char lname[size], int phone[11], int birth[7])


I want to sort the first names by alphabetical order.
* Your function name is misleading. Are you trying to display the contents of a file or to read from a file ? please do use a more descriptive name.
Well, you could construct your function heading like this:
1
2
void functioName(string firstname[], string lastname[], 
				int phonenumber[], int birth[], size_t size)
Last edited on
Topic archived. No new replies allowed.