Could anyone give me an sample how to create a 2D char array in C by passing the variable for the array length.
//Current program
int i;
int seq_cnt;
exec sql
select count(0)
into seq_cnt
from table;
char tmp1[50][5+1];
char tmp2[50][5+1];
for(i=0;i < seq_cnt ; i++){
strcpy(tmp1[i],"something");
strcpy(tmp2[i],"something");
}
Now what I want is for the array size of tmp1 and tmp2, I want to use the seq_cnt to declare the actual size of tmp1 and tmp2 instead of hardcode it (50).
like:
char tmp1[seq_cnt][5+1];
char tmp2[seq_cnt][5+1];
I'm new to C.
char tmp1[seq_cnt][5+1]; char tmp2[seq_cnt][5+1];should work if you are using C99+. Or you can resort to dynamically allocating memory usingmalloc. Note:"something"won't fit into an array of size5 + 1