Dann Corbit wrote:
"Dann Corbit" <dc*****@connx. com> wrote in message
news:e7******** **@nntp.aioe.or g...
Maybe something like this:
#include <stdio.h>
#include <string.h>
typedef char Label[3];
int main(void)
{
size_t i;
Label mystrArray[100]={0};
for (i = 0; i < 100; i++)
sprintf(mystrAr ray[i], "%02d", i);
for (i = 0; i < 100; i++)
puts(mystrArray[i]);
return 0;
}
sprintf solves the first problem, but the array is still confusing me...here's the actual code:
char *labelArray [(4*MAX2*MAX2)+1];
int mkLabels(void) {
char blkid[3],colid[3],rowid[3],digit[3];
int i,j,colnum,rown um;
pCELL pointer = mArray[0][0][0][0];
for (i=0;i<n4;i++) {
printf("Making column labels for square %d\n",i);
char alabel[6] = "a";
char blabel[6] = "b";
char clabel[6] = "c";
char dlabel[6] = "d";
sprintf(blkid, "%02d",poin ter->block);
int sindex = ilookup(pointer->symbol); /*printf("sindex is %d\n",sindex);*/
sprintf(digit, "%02d",sind ex);
/* For columns and rows we have to do some annoying mapping to a two-digit identifier - mArray's fault */
colnum = (pointer->column)+((poin ter->block%n)*n);
sprintf(colid, "%02d",coln um);
rownum = (pointer->row)+((point er->block/n)*n);
sprintf(rowid, "%02d",rown um);
printf("blkid is %s, colid is %s, rowid is %s, digit is %s\n",blkid,col id,rowid,digit) ;
strcat(alabel,r owid); strcat(alabel,c olid);
labelArray[i] = alabel;
strcat(blabel,d igit); strcat(blabel,r owid);
labelArray[i+n4] = blabel;
strcat(clabel,d igit); strcat(clabel,c olid);
labelArray[i+n4+n4] = clabel;
strcat(dlabel,d igit); strcat(dlabel,b lkid);
labelArray[i+n4+n4+n4] = dlabel;
1) printf("alabel is %s, blabel is %s, clabel is %s, dlabel is %s\n",alabel,bl abel,clabel,dla bel);
pointer = pointer->next_in_puzzle ;
}
2) printf("\nConte nts of labelArray:\n") ;
for (j=0;j<4*n4;j++ ) {
printf("%s ",labelArra y[j]);
}
printf("\n\n");
return 0;
}
This compiles and runs ok but doesn't work as required since each update to alabel, blabel etc changes those objects that all
the pointers point to, so I am not storing new labels just overwriting the same ones (the print contents at 2) confirms that).
Note I want the whole structure labelArray to be available globally which is another problem with the code above.
So I need to do something differently, perhaps the 2d array, but I couldn't get that to compile. At least the values at 1) are
correct, just the structure is wrong.