I have 2D array I want populate then compare to literal
below is compare code, i try different things with no success
char** list;
load(list);
if(strcmp(list[0], "aasdf"))
{
printf("win\n");
}
the above segfaults on strcmp
load function
void load(char **list)
{
int MAX_NUM_LINES = 1000;
FILE *fp;
list = malloc(MAX_NUM_LINES*sizeof(char*));
fp = fopen("list", "r");
line_ct = 0;
char line[256];
while ( fgets(line, 256, fp) != NULL )
{
int len = strlen(line);
list[line_ct] = malloc(len * sizeof(char));
strcpy(list[line_ct], line);
line_ct++;
if(line_ct == MAX_NUM_LINES)
{
break;
}
}
fclose(fp);
}
any ideas on why is segfault?
also i try before strcmp
printf("Line: %s\n", *list[0]);
it segfault to