I need to read a .txt file as shown below. Might be hard to read, but it is shown as a 5 by 7 table. I need to input all the data from the .txt file into the array using the code below. However, only the top row is inserted and everything else is messed completely. It is completely skipping over jdark@att.net, for example. Please help.
bham@gnet.com Blake Ham squid62 1987 U Teacher
jdark@att.net Jim Dark gymrat321985 A Master
hdgreen@lakes.netHannah Green flower222007 U Apprentice
tsmith@dna.com Tom Smith tuna20 2000 U Teacher
jarrow@pnet.com James Arrow ahoy10 2005 U Apprentice
1 2 3 4 5 6 7 8 9 10 11 12
for (int x = 0; x < 6; x++)
{
for (int y = 0; y < 8; y++)
{
inputFile >> theAccounts[x][y];
}
cout << endl;
}
If the array is 5 x 7, then the valid indices are 0,1,2,3,4 and 0,1,2,3,4,5,6. With x < 6 (up to 5) and y < 8 (up to 7), the code is going out of bounds on the array.
Nvm, the array is reading correctly from the .txt file now. Thank you. However, I need help sorting the array above by last name in alphabetical order. This is my current code, its does not work at all. Please help.
You need to swap an entire row of data. Right now there's a temp variable holding just one cell of the table for swapping, the others just get overwritten (and the last two columns, 5 and 6 aren't included ?). If you're sorting by last name, the y value would be 2, not 1, I think, if this is what you want to end up with.
1 2 3 4 5
jarrow@pnet.com James Arrow ahoy10 2005 U Apprentice
jdark@att.net Jim Dark gymrat 321985 A Master
hdgreen@lakes.net Hannah Green flower 222007 U Apprentice
bham@gnet.com Blake Ham squid62 1987 U Teacher
tsmith@dna.com Tom Smith tuna20 2000 U Teacher