Hello MR members,
I have spent three hours trying to figure out how to read in the data of a group of people and store the information into an array of structures (struct Node) and then print out the array. I was given the following structure definition to work with:
I understand the concept of arrays and structures (a group of arrays), but I can't find a good example that is similar enough to my problem to study.
I am trying to read the following text from file "a6.txt" into an array of structures:
Here is the C++ I have so far:
Any tips or guidance is appreciated.
Thanks in advance,
- Cory
I have spent three hours trying to figure out how to read in the data of a group of people and store the information into an array of structures (struct Node) and then print out the array. I was given the following structure definition to work with:
Code:
struct Node { char name[20];
int ID; int distance;
};
I understand the concept of arrays and structures (a group of arrays), but I can't find a good example that is similar enough to my problem to study.
I am trying to read the following text from file "a6.txt" into an array of structures:
April,Joe
3120
12
Matthews,Jocob
4592
39
Garfield,Kitty
8917
33
Lake,Bill
2233
21
Jones,Betty
8912
18
Goodman,Betty
4598
19
Lands,Norman
7812
36
Johnson,Carl
8917
29
Here is the C++ I have so far:
Code:
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
int READ(char txtfile[10]; int numarray[10]; int counter;)
{
ifstream filename;
filename.open (txtfile);
while (!filename.eof())
{
filename >> numarray [counter];
cout << numarray [counter] << endl;
counter++;
};
};
int main()
{
char txtfile[]="a6.txt";
int size=10;
int numarray [size];
int r;
r= READ();
cout<< r;
system("PAUSE");
return EXIT_SUCCESS;
}
Any tips or guidance is appreciated.
Thanks in advance,
- Cory