Can anyone show me what is wrong here? Segmentation fault
I have to write a program that reads in a list of names of people and their age and then sort the names alphabetically. I have to use fgets() to read in each line and then use strtok() to partition the first name/last name/ages. Suppose the text file "names.txt" looks like this:
Ryan, Elizabeth 62
McIntyre, Osborne 84
DuMond, Kristin 18
This is my code for reading from this file:
Code:
void read_file()
{
char **first_name;
char **last_name;
char line[80];
FILE *fp = fopen("names.txt", "r");
*first_name = malloc(count * sizeof(char)); //count is the number of names in file
*last_name = malloc(count * sizeof(char)); //so in this case count = 3
fgets(line, 80, fp);
(*first_name)[0] = strtok(line, ", \n");
printf("%s", (*first_name)[0]);
}
Right now I know it only reads the first line, I just want to check to make sure this works first. However, when I compile with gcc I get this message:
Code:
sort.c:23: warning: assignment makes integer from pointer without a cast
And when I run the program I get a segmentation fault. Can anyone tell me what is wrong with the code above? Any help is appreciated!