Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!zephyr.ens.tek.com!tektronix!reed!intelhf!ichips!inews!pima!bhoughto From: bhoughto@pima.intel.com (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: casting ints and floats to char* Message-ID: <4033@inews.intel.com> Date: 26 Apr 91 02:46:08 GMT References: <6185@mahendo.Jpl.Nasa.Gov> Sender: news@inews.intel.com Organization: Intel Corp, Chandler, AZ Lines: 41 In article <6185@mahendo.Jpl.Nasa.Gov> robert@triton.JPL.NASA.GOV writes: >Hello C people, > I'm trying to have a char* array point to different types, i.e >hold addresses of ints,floats, and longs. > >I want to be able to do the following: > >void has_to_be_done_this_way() >{ >char *ptr[12]; Use void *ptr[12]; instead. >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])); Use sscanf(buf,"%2d %5ld %15lf",(int *)ptr[0],(long *)ptr[1],(double *)ptr[2]); instead. >} You might also look into declaring an array of unions rather than one of pointers. --Blair "If you want a more perfect union, talk to Jefferson and Madison..."