Hi, all--
This program is meant to read a list of names and ages from a file and store them in arrays. Unfortunately, I've only gotten as far as dynamically allocating the arrays, and I'm already getting warnings. Here's my code:
Code:
void read_file(char (*last_names)[80][20], char (*first_names)[80][20], int (*ages)[80][20], int *count, char filename[80])
{
int i;
FILE *fp;
fp = fopen(filename, "r");
fscanf(fp, "%d", count);
for(i = 0; i < *count; i++)
{
(*last_names)[i] = (char *)malloc(20 * sizeof(char));
(*first_names)[i] = (char *)malloc(20 * sizeof(char));
(*ages)[i] = (int *)malloc(sizeof(int));
}//for i = 0
}//read_file
void sort(char last_names[80][20], char first_names[80][20], int ages[80])
{
}//sort
void print_list(char last_names[80][20], char first_names[80][20], int ages[80])
{
}//print_list
void deallocate(char last_names[80][20], char first_names[80][20], int ages[80])
{
}//deallocate
int main(int argc, char *argv[])
{
int count = 0, ages[count];
char last_names[count][21], first_names[count][21], filename[80];
strcpy(filename, argv[1]);
read_file(&last_names, &first_names, &ages, &count, filename);
sort(last_names, first_names, ages);
print_list(last_names, first_names, ages);
deallocate(last_names, first_names, ages);
return 0;
}//main
For the lines in red, I get "error: incompatible types in assignment". For the bits in green, I get "passing argument from incompatible pointer type". If not for the voice of God saying otherwise, I'd say everything checks out. Help?