I'm sure I'm just making a stupid error but I am getting a seg fault when I fscanf on line 15. Do you know the reason? Btw I'm not done with the program.
Code:#include <stdio.h> 4 #include <string.h> 5 #include <stdlib.h> 6 void readnames(); 7 void sort(); 8 void write_names(); 9 void free_memory(); 10 11 int main(int argc, char *argv[]) 12 { 13 int amount; 14 FILE *fp = fopen(argv[1], "r"); 15 fscanf(fp, "%d", &amount); 16 char** last = (char **)malloc(amount*sizeof(char*)); 17 int i; 18 for (i=0; i<amount; i++) 19 { 20 last[i] = (char*)malloc(15*sizeof(char)); 21 }//creating last array 22 char** first = (char **)malloc(amount*sizeof(char*)); 23 for (i=0; i<amount; i++) 24 { 25 first[i] = (char*)malloc(15*sizeof(char)); 26 }//creating first array 27 char* middle = (char*)malloc(sizeof(char)); 28 readnames(amount, argv[1], last, first, middle); 29 30 31 32 return 0; 33 }//main



1Likes
LinkBack URL
About LinkBacks


