#include #include typedef struct st_stmt_fetch { char is_open; unsigned long *out_data_length; char **out_data; unsigned column_count; unsigned row_count; } Stmt_fetch; static int stmt_fetch_fetch_row(Stmt_fetch *fetch) { unsigned i; if (fetch->row_count == 0) { fetch->row_count= 100; printf("Program will crash in this for loop\n"); for (i= 0; i < fetch->column_count; ++i) { printf("Never reached, unless the line below is uncommented\n"); fetch->out_data[i][fetch->out_data_length[i]]= '\0'; /* Not even the below statement works */ //fetch->out_data[i][0]= 0; } } else fetch->is_open= 0; return 1; } int main(int argc, char **argv){ unsigned query_count= 2; unsigned open_statements= query_count; Stmt_fetch *fetch_array= (Stmt_fetch*) calloc(sizeof(Stmt_fetch), query_count); Stmt_fetch *fetch; for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) { fetch->column_count= 2; fetch->out_data= (char**) calloc(fetch->column_count, sizeof(char*)); fetch->out_data_length= (unsigned long*) calloc(fetch->column_count, sizeof(unsigned long)); fetch->row_count= 0; fetch->is_open= 1; } while (open_statements) { for (fetch= fetch_array; fetch < fetch_array + query_count; fetch++) { if (fetch->is_open && stmt_fetch_fetch_row(fetch)) { open_statements--; } } } return 0; }