Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!wuarchive!rex!rouge!gator.cacs.usl.edu From: pcb@gator.cacs.usl.edu (Peter C. Bahrs) Newsgroups: comp.lang.c Subject: realloc questions Message-ID: <4563@rouge.usl.edu> Date: 26 Feb 90 19:36:02 GMT Sender: anon@rouge.usl.edu Distribution: usa Organization: The Center for Advanced Computer Studies, USL Lines: 36 This may be a naive discussion but here goes... I want to create an N (2 for now) dimensional datum of long integers. typedef struct a { int row, col; long **arr} A; A *temp; temp=(A *) calloc (1, sizeof(A)); /* then initialize row and col ... */ A->arr=(long *)calloc (A->row, sizeof(long *)); for (j=0;jrow;j++) A->arr[j] = calloc(col,sizeof(long)); 1) I should now be able to index as A->arr[j][k], correct? 2) or should type A contain long *arr[] instead? Now I want to redimension the type to a new_row and new_col. A->arr=(long *) realloc ((char *)&A->arr, new_row*sizeof(long *)); for (j=0;jnew_row;j++) A->arr[j] = realloc(new_col,sizeof(long)); 3) This doesn't work (sometimes). I understand realloc will retain values of the minimum of the old and new dimensions, and 'frees' memory if the new is smaller. Any suggestions? /*----------- Thanks in advance... --------------------------------------+ | Peter C. Bahrs | | The USL-NASA Project | | Center For Advanced Computer Studies INET: pcb@gator.cacs.usl.edu | | 2 Rex Street | | University of Southwestern Louisiana ...!uunet!dalsqnt!gator!pcb | | Lafayette, LA 70504 | +-----------------------------------------------------------------------*/