File Reading Strings and Integers

I'm trying to read a file that contains integers and strings called club.txt that has the following data.

4
Ami
Ann
Ben
Dan
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)
{

//Local Declarations
int data_in;
int loader;
FILE* fp_data;

//Statements
loader = 0;

if ((fp_data = fopen ("clubs.txt", "r")) == NULL)
{
printf("Error opening file\a\a\n") ,
exit (100);
}

while (loader < size && fscanf(fp_data, "%d", &data_in) != EOF)
{
if(loader == 0)
{
size = data_in;
printf("%d", size);
loader++;

}
for (loader = 1; loader <= (size * 3) + 1; loader++)
names[loader - 1] = data_in;
break;
}
}


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 !

Updated.

int get_data (int students_friends[][MAX_STUDENTS],
char names[][MAX_STUDENTS], int size)
{

//Local Declarations
int data_in;
int loader;
FILE* fp_data;

//Statements
loader = 0;

if ((fp_data = fopen ("clubs.txt", "r")) == NULL)
{
printf("Error opening file\a\a\n") ,
exit (100);
}

while (fscanf(fp_data, "%d", &data_in) != EOF)
{
if(loader == 0)
{
size = data_in;
printf("%d", size);
loader++;
continue;
}
if (loader == 1 && loader <= (size * 3))
{
for (int r = 0; r < size; r++)
{
for (int c = 0; c < size; c++)
{
names[r][c] = data_in;
printf("%c", names[r][c]);
}
loader++;
}
}
}
}
Topic archived. No new replies allowed.