This is a sample of code I'm dealing with.
switch(n){
case 1:
char tcol[4][100]={"Canadian Order","Achat Francais","china"};
char trow[7][100]={"Item","Price","Qty","Total","Tax","Grand total"};
Htable(trow,tcol,7,4,"");
break;
case 2:
char tcol[3][100]={"Other column 1","2nd column"};
char trow[4][100]={"1st row","2nd row","Row 3"};
Htable(trow,tcol,4,3,"");
break;
case n:
...
}
Basically I'm creating a function Htable that takes the row and column names for an HTML table and the 3rd and 4th argument is the number of rows and columns.
The problem I have is the compiler thinks I'm redefining the array even though each definition is accessible only once from a switch branch. Here's the errors:
./html2.c:118: error: redefinition of ‘tcol’
./html2.c:110: error: previous definition of ‘tcol’ was here
./html2.c:119: error: conflicting types for ‘trow’
./html2.c:111: error: previous declaration of ‘trow’ was here
And that keeps happening for each block of code I have. The only partial solution I could come up with is the following:
char tcol[1][4][100]={"Canadian Order","Achat Francais","china"};
char trow[1][7][100]={"Item","Price","Qty","Total","Tax","Grand total"};
char trow[2][4][100]={"1st row","2nd row","Row 3"};
char tcol[2][4][100]={"Other column 1","2nd column"};
switch(n){
case 1:
Htable(trow[1],tcol[1],7,4,"");
break;
case 2:
Htable(trow[2],tcol[2],4,3,"");
break;
case n:
...
}
Is there a simple way to do this where the C compiler accepts it without having to add fancy code to separate the strings?