[comp.lang.c] Data Structure question

rg2c+@andrew.cmu.edu (Robert Nelson Gasch) (02/02/91)

Please excuse me if this is basic, but I'n no C hack and am having
problems with this as I only recently started programming in C. Given 
the following declarations (excuse the long winded format, but this
is the most explicit notation to me)

typedef struct{
	int data, value, frequency;
	} datatype;
	
typedef datatype data_array[MAXNUM];
typedef data_array *data_array_pointer;
typedef data_array_pointer pointer_matrix_type[MAXNUM];


How do I access the individual data elements once I malloc() the structure?
I've been trying to get this right for 2 days by now but managed to produce
only system errors. If this were a simple 2 dimensional array, the notation
would be
    array[x][y].data = whatever;

Introducing pointers into the data structure makes things harder though,
so I have no clue on how to correctly access the cells. If anybody could
shed some light on this, I'd greatly appreciate it.

Thanx a lot ---> Rob

bliss@sp64.csrd.uiuc.edu (Brian Bliss) (02/06/91)

if you have:

typedef struct{
	int data, value, frequency;
	} datatype;
	
typedef datatype data_array[MAXNUM];
typedef data_array *data_array_pointer;
typedef data_array_pointer pointer_matrix_type[MAXNUM];
pointer_matrix_type array;

then to access, say the data field, of each datatype struct, say

(*array[i])[j].data

bb

guy@hpgnd.grenoble.hp.com (Guy DUBRISAY) (02/09/91)

I suppose that you declared something like 

	pointer_matrix_type array ;

You should be able to acces the cells thus

    (*array[x])[y].data = whatever;

Hope this helps ...

Guy.
----------