I'm trying to read data from a file into parallel arrays. It's a list of names (first and last), dates, and scores. I then need to sort those arrays by any one of the four things being read in (name, date, score).

This is what I have so far...

Code:
 
#include <stdio.h>
#include <string.h>

#define NMAX 200
#define MAXLEN 50

int main(void)
{
	int num = 0;
	int score[NMAX];
	char lastname[NMAX][MAXLEN];
	char firstname[NMAX][MAXLEN];
	char date[NMAX][3];

	FILE *ifile;

	ifile = fopen("data.txt", "r");

	while (fscanf(ifile, "%s %s %s %d", lastname[num], firstname[num],
		date[num], &score[num]) != EOF) {
			printf("%5d %-14s %-14s %3s\n", score[num], firstname[num],
				lastname[num], date[num]);		
	numop++;
	}
	
	fclose(ifile);
	
	return(0);
}

1) I imagine I'll want to dynamically allocate memory for my arrays, but I'm confused as to how to do this. Do you scanf the file to see how long it is, then use that value w/ malloc to allocate the array before you actually add values as elements? Or do you constantly make the array bigger/smaller with each element that you add/subtract? Also, I define some macros in the beginning to make my arrays "big enough" when declaring them. When I implement dynamic allocation, will I still need these macros?

2) In the while loop, lastname, firstname, and date, are all "scanned" in without using an "&", but score requires an "&"? Why is this?

3) When sorting the data, do I actually want to sort the data--as in switching which values are held at which address for all four arrays? Or would it be more practical to sort an array of indices (or pointers) of the arrays?

If questions similar to mine have been answered elsewhere, I apologize. If so, please direct me to the proper location.

Thanks