|I'm trying to read a file that contains integers and strings called club.txt that has the following data.|
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
My problem is reading the data into the appropriate variables. The first value (integer) 4 needs to be read into an integer size. This much I have figured out how to do, the rest is beyond me though.
I need to read the names Ami, Ann, Ben, Dan into a string array. Then read the following 1s and 0s into a 2D integer array. My biggest problem is that I have no way of counting which line is read. Any help?
This is what I have so far:
int get_data (int students_friends[MAX_STUDENTS],string names, int size)
loader = 0;
if ((fp_data = fopen ("clubs.txt", "r")) == NULL)
printf("Error opening file\a\a\n") ,
while (loader < size && fscanf(fp_data, "%d", &data_in) != EOF)
if(loader == 0)
size = data_in;
for (loader = 1; loader <= (size * 3) + 1; loader++)
names[loader - 1] = data_in;
I'm also considering making names a char 2D array that reads each char individually.
This is for an intermediate C++ class so we havent covered vectors or anything confusing yet.
Thanks in advance !