Trouble Opening a .txt File

In my program that I am making, I am accessing a file that has a full name, a phone number, and a birth date in it, all with spaces between each piece, and storing each piece in its own array. However, after it opens I do a priming read, and when it does that, the first and last name arrays will hold the name, but the phone number and birth date remain unchanged. I then have a while loop to write the rest of the file onto the respective arrays, but none of the arrays are changed during that loop, only the counter goes up. The path for the file is correct.

If anyone has an idea of what the problem is, please let me know.

Here is where I opened the file:
1
2
3
4
5
6
7
8
9
10
11
ifstream readFile;

	readFile.open("AddressBook.txt");

	if (readFile.is_open())
	{
		num_records = ReadData(readFile, firstName, lastName, phoneNumber, birthDate);
		readFile.close();
}
else
		cout << "Error: Unable to open file.\n" << endl;


Here is the function that reads the file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  int ReadData(ifstream & readFile, char firstName[][16], char lastName[][32], int phoneNumber[], int birthDate[])
{
	int count = 0;

		readFile >> lastName[count]
			>> firstName[count]
			>> phoneNumber[count]
			>> birthDate[count];

		while (!readFile.eof())
		{
			count++;

			readFile >> lastName[count]
				>> firstName[count]
				>> phoneNumber[count]
				>> birthDate[count];
		}

	return count;
}


Any help is greatly appreciated!
Please give us an input example.
If I were to enter:

Smith Joe 1234567890 1174

The long number is the phone number, the other one is the birth date in the order of month, day, year.
Did you allocate the arrays memory appropriately?
Try checking the error/eof state of readFile after the read statements.
Topic archived. No new replies allowed.