Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!ucbvax!AB.ECN.PURDUE.EDU!del From: del@AB.ECN.PURDUE.EDU (del Amitri) Newsgroups: comp.lang.c Subject: array assignment Message-ID: <9005022225.AA19329@ab.ecn.purdue.edu> Date: 2 May 90 22:25:31 GMT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 62 winner takes all. from within a teeney-little routine (func()), i need to assign values to some arrays, whose address and size i pass to that array. the actual assignemnt syntax within func() has me baffled... thanks del@ab.ecn.purdue.edu ------------------------------------------------------------------------------- the array types are declared by the union: union utyp { int *_int; float *_float; char **_char; } #define _INT 1 #define _FLT 2 #define _ALP 3 so: main() { float a[10][3]; char b[10][3][20]; int c[10][3]; func(a, _FLT, 10, 3); func(b, _ALP, 10, 3); func(c, _INT, 10, 3); } func(var, typ, ysize, xsize) union utyp *var; int typ, ysize, xsize; { if (!ysize) ysize = 1; if (!xsize) xsize = 1; for (i = 0 ; i < ysize ; i++) for (j = 0 ; j < xsize ; j++) switch (typ) { /* depending upon the incoming array type, assign values into that incoming array (essentially need to do x[i][j] = value) the values being assigned are globally accessible. */ /* so, what is the syntax for each case? */ case _INT: var->_int[i * xsize + j] = value; case _FLT: var->_float[i * xsize + j] = value; case _ALP: strcpy(var->_char[i * xsize + j], value); } }