Turbo C far pointer problem
marwk at levels.sait.edu.au
marwk at levels.sait.edu.au
Thu Jan 3 02:05:55 AEST 1991
> int maxrows, maxcols;
> char **array;
>
> maxrows = ...whatever...
> maxcols = ...whatever...
>
> array = (char **) malloc(maxcols * sizeof(char *));
Use maxrows in the above line.
>
> for(x=0; x < maxrows; x++) /* !!! do not change this line */
> array[x] = (char *) malloc(maxrows);
Use maxrows in the above line
Your first malloc allocates MAXCOLS column pointers.
The second allocates MAXROWS rows for MAXROWS columns, not MAXCOLS columns.
The usual matrix use requires array[r][c] to refer to the r'th row and the
c'th column - the changes above will fix this.
Perhaps your UNIX program has a bug it in now? ;-)
I have tested my solution with TC 2.01.
Ray
More information about the Comp.lang.c
mailing list