#char (*tp[N])[] ?
Help!
I'm having a difficult time figuring out how to declare something
in c: I've got several arrays of char *, defined in different header
files — they're all constants, but the strings are various lengths,
and the arrays are of different sizes. I want to make an array
of pointers to these arrays… and it's giving me a great headache!
Here's the best (ie, fewest compile errors) that I've done so far:
(extracts from code, with much unrelated stuff left out)
In "mt.h":
#ifndef MT_H
#define MT_H
#define MT_NFIELDS 15
#ifdef _FB_MT
char *mt_fieldnames[MATSTYLE_NFIELDS] = { "MAT_NAME",
"INDEX_OF_R",
"SURF_DEPT",
"FIN_DEPT",
"DAYS" };
#else
extern char *mt_fieldnames[MT_NFIELDS];
#endif
#endif
(note "xx_fieldnames" below is defined in another include file
similar to the one above; different number of strings of differing
length.)
In "fb.h":
#ifndef _FB_H
#define _FB_H
#include <mt.h>
#include <that other header file>
#define N_FB_FILES 2
#ifdef _FB_FILES
#define WHERE /*public*/
/* …an N_FB_FILES-element array of ptrs to x-element arrays of char? */
WHERE char (*db_fieldnames[N_FB_FILES])[] = { &xx_fieldnames,
&mt_fieldnames };
#else
#define WHERE extern
WHERE char (*db_fieldnames[N_FB_FILES])[];
#endif
#endif
If anyone cares to, please feel free to give me some "pointers" on
how to do this…. tutorial book references appreciated too ( I've got
K&R & the Waite-group's book)….
Thanks…. 🙂
(auto-piloted from)
JcP