Xref: utzoo comp.lang.c:35110 comp.os.msdos.programmer:2739 Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!brolga!lingua.cltr.uq.OZ.AU!jcl From: jcl@lingua.cltr.uq.OZ.AU (Jean-Claude Lacherez) Newsgroups: comp.lang.c,comp.os.msdos.programmer Subject: Problem with TURBO C and pointers Message-ID: <1991Jan9.012509.22427@lingua.cltr.uq.OZ.AU> Date: 9 Jan 91 01:25:09 GMT Organization: Centre for Language Teaching and Research, Uni of Queensland, AUSTRALIA. Lines: 91 Thanks to all those who replied to my question concerning dynamic dimensioning of arrays. Unfortunately the problem is not solved: 1/ First there was a confusing typo in my sample code, as follows: int maxrows, maxcols; char **array; maxrows = ...whatever... maxcols = ...whatever... array = (char **) malloc(maxcols * sizeof(char *)); for(x=0; x < maxrows; x++) ^^^^^^^ ^ | array[x] = (char *) malloc(maxrows); Sorry about that. This is not what I have in my original code and this is not the source of my problem. 2/ A couple of people pointed out that far pointers wrap at 64k, and suggested that I use huge pointers (at the cost of efficiency). However, the test program below which dimensions a really tiny array should not cause wrapping, and still it does not work. #include #define NB_OF_ROWS 5 #define ROW_LENGTH 4 char *string[] = {"123", "456", "789", "ABC", "DEF"}; main() { char **array; int x, y; array = (char **) malloc(NB_OF_ROWS * sizeof(char *)); if (array == NULL){ puts("Fail 1"); exit(0); } else puts("ok "); for(x=0; x < NB_OF_ROWS; x++) { printf("Making row No %d\n", x); array[x] = (char *) malloc(ROW_LENGTH ); if (array[x] == NULL) { puts("Fail 2"); exit(0); } strcpy(array[x], string[x]); printf("array[%d] as string: %s\n", x, array[x]); printf("By characters: "); for(y=0; y < ROW_LENGTH; y++) printf("%c ",array[x][y]); putchar('\n'); } strcpy(array[0],"abc"); strcpy(array[1],"def"); strcpy(array[2],"hij"); strcpy(array[3],"klm"); strcpy(array[4],"nop"); printf ("\nNew values:\nas strings:"); for(x=0; x