2D array of chars

Here is my issue. Inside the function get_data the 2D array names prints and operates fine. However, once in main. It prints this:
Am

An

Be

Dan

Instead of:

Ami
Ann
Ben
Dan

Heres the code:

int main (void)
{
//Local Declarations
int size;
int students_friends[MAX_STUDENTS][MAX_STUDENTS] = { {0 } };
int number_friends[MAX_STUDENTS];
char names[MAX_STUDENTS][NUM_NAMES] = { {0} };


//Statements
size = get_data(students_friends, names, size);
frequency_friends(students_friends, number_friends, size);
//list_friends(students_friends, names,number_friends, size);

for (int row = 0; row < size; row++)
for (int col = 0; col < size; col++)
printf("%c", names[row][col]);


}

int get_data (int students_friends[][MAX_STUDENTS],char names[][NUM_NAMES],
int size)
{
//Local Declarations
int data_in;
char name_data;
int loader;
FILE* fp_data;
char whitespace;
whitespace = NULL;

//Statements
loader = 0;

//Checks that file opens
if ((fp_data = fopen ("clubs.txt", "r")) == NULL)
{
printf("Error opening file\a\a\n") ,
exit (100);
}
//Reads first integer in text file and assigns it to size
if (fscanf(fp_data, "%d", &data_in) != EOF && loader == 0)
{
size = data_in;
printf("%d", size);
loader++;
}
//Reads the names in text file into 2D array
for (int row = 0; row < size; row++)
for (int col = 0; col < size; col++)
if (loader > 0 && loader <= (size * size) &&
fscanf(fp_data, "%c", &name_data) != EOF
&& name_data != whitespace)
{
names[row][col] = name_data;
printf("%c", names[row][col]);
loader++;
}
printf("\n");
//Reads the remaining numbers in text file into 2D array
for (int row = 0; row < size; row++)
for (int col = 0; col < size; col++)
if (loader > (size * size) && loader <= (size * size) + (size * size) &&
fscanf(fp_data, "%d", &data_in) != EOF)

{
students_friends[row][col] = data_in;
printf("%d ", students_friends[row][col]);
//After four numbers, prints a new line
if (!(loader % size))
printf("\n");
loader++;
}
return size;
}
Topic archived. No new replies allowed.