Turbo C large character array

Evan Marshall Manning manning at gap.caltech.edu
Wed Aug 1 01:29:32 AEST 1990


doug at ozdaltx.UUCP (Doug Matlock) writes:


>If all you need is a very large array, and you always plan to access its
>elements through a pair of indicies, I suggest you use the tack taken in
>"Numerical Recipes in C".  A character "array" is defined as
>char **x;

>and allocated on the heap as

>x = (char **)malloc(num_rows*sizeof(char));
			      ^^^^^^^^^^^^ try sizeof(char *)!!!!
>for (i=0; i<num_rows; i++)
	x[i] = (char *)malloc(num_cols_in_row[i]*sizeof(char));

A char is rarely big enough to hold a char *.

-- Evan

***************************************************************************
Your eyes are weary from staring at the CRT for so | Evan M. Manning
long.  You feel sleepy.  Notice how restful it is  |      is
to watch the cursor blink.  Close your eyes.  The  |manning at gap.cco.caltech.edu
opinions stated above are yours.  You cannot       | manning at mars.jpl.nasa.gov
imagine why you ever felt otherwise.               | gleeper at tybalt.caltech.edu



More information about the Comp.lang.c mailing list