Need help with pointer to array[][]

hsgj at batcomputer.UUCP hsgj at batcomputer.UUCP
Sun Feb 8 10:57:44 AEST 1987


An application I have requires an array to hold filenames.  Each element
of this array must be 32 chars long, and I would like 16 elements.
I used to be using:
     static char fnames[16][32];

However, I decided it would be better to malloc this space instead of
having it static.  How do I declare a pointer to a two-d array?
My new version is:
     char *fnames;                    /* What is correct declaration? */
     fnames = malloc(16*32);
     GetFileNames(fnames);
     for (i = 0; i < 16; i++)
        printf("%s\n",fnames[i*32]);  /* this is wrong, no? */

I am sure that this is bad practice, and would like to be informed
of the 'correct' way to do this.

==> If you are kind enough to reply, please do so via mail. <==
==> This is because I am quite far behind in comp.lang.c.   <==

-- Dan Green
-- 
ARPA:  hsgj%vax2.ccs.cornell.edu at cu-arpa.cs.cornell.edu
UUCP:  ihnp4!cornell!batcomputer!hsgj   BITNET:  hsgj at cornella



More information about the Comp.lang.c mailing list