Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!agate!ucbvax!bloom-beacon!eru!hagbard!sunic!sics.se!ifi!jar From: jar@ifi.uio.no (Jo Are Rosland) Newsgroups: comp.lang.c Subject: Re: casting ints and floats to char* Message-ID: Date: 25 Apr 91 16:49:22 GMT References: <6185@mahendo.Jpl.Nasa.Gov> Sender: jar@ifi.uio.no (Jo Are Rosland) Organization: University of Oslo, Norway Lines: 54 In-Reply-To: robert@nereid.jpl.nasa.gov's message of 25 Apr 91 00: 10:47 GMT In article <6185@mahendo.Jpl.Nasa.Gov> robert@nereid.jpl.nasa.gov (Robert Angelino) writes: I want to be able to do the following: void has_to_be_done_this_way() { char *ptr[12]; int i; long j; double p; ptr[0] = &i; ptr[1] = &j; ptr[2] = &p; sscanf(buf,"%2d %5ld %15lf",&(*ptr[0]),&(*ptr[1]),&(*ptr[2])); } Does it have to be a char * array? How about: 1. typedef union { int *ip; long *lp; double *dp; } NUMP; void how_about_this_way() { NUMP ptr[12]; int i; long j; double p; ptr[0].ip = &i; ptr[1].lp = &j; ptr[2].dp = &p; sscanf(buf, "%2d %5ld %15lf", ptr[0].ip, ptr[1].lp, ptr[2].dp); } 2. typedef struct { int i; long l; double d; } ILD; void son_of_how_about_this_way() { ILD trip[4]; sscanf(buf, "%2d %5ld %15lf", &trip[0].i, &trip[0].l, &trip[0].d); } Why does it "have to be done that way", anyway? Just curious... -- Jo Are Rosland jar@ifi.uio.no