I am having an issue where some global char pointer arrays that I am trying to initialize become full of garbage data after the function that I initialized them in goes out of scope.
char *dept_vals[255];
char *num_vals[255];
char *day_vals[255];
char *bldg_vals[255];
char *instr_vals[255];
int start_vals[255];
int end_vals[255];
int sect_vals[255];
int room_vals[255];
int idx;
static int callback(void *NotUsed, int argc, char **argv, char **azColName)
{
int i = 0;
while(i < argc)
{
dept_vals[idx] = argv[i++];
num_vals[idx] = argv[i++];
start_vals[idx] = atoi(argv[i++]);
end_vals[idx] = atoi(argv[i++]);
day_vals[idx] = argv[i++];
sect_vals[idx] = atoi(argv[i++]);
bldg_vals[idx] = argv[i++];
room_vals[idx] = atoi(argv[i++]);
instr_vals[idx] = argv[i++];
idx++;
}
return 0;
}
When I print the values in a different function, the contents are incorrect. However, the values in the integer arrays that I initialized in the same function have the right values. I suspect that the way I am initializing the char pointer arrays is causing unexpected behavior, but I'm not completely sure what is the correct way to initialize them in this situation.