Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!hao!gatech!uflorida!codas!killer!tness1!mechjgh From: mechjgh@tness1.UUCP (Greg Hackney 214+464-2771) Newsgroups: comp.sys.pyramid Subject: Re: Wrapper function to sprintf Message-ID: <429@tness1.UUCP> Date: 3 Mar 88 03:35:29 GMT References: <232400003@prism> Reply-To: mechjgh@tness1.UUCP (Greg Hackney 214+464-2771) Organization: S.W. Bell, Network Engineering Lines: 47 In article <232400003@prism> atj@prism.UUCP writes: > >Hi, I am having a little problem with developing a "wrapper" to sprintf. >What I wish to do is write a "dialog_box" routine that takes the >same parameters as printf. So, I have the following: >dialog_box(cs, args) >char *cs; >{ > char buffer[512]; > > sprintf(buffer, cs, args); I couldn't figure out how to pass an array of pointers to sprintf() and make it work correctly, but here's a dippy way that does work. -- Greg Hackney Southwestern Bell telephone Co. mechjgh@tness1.UUCP ------------------ #include #include main() { dialog("%s\t%s\t%s", "one", "two", "three"); } char * dialog(format,va_alist) char *format; va_dcl { va_list ap; char *args[10]; char buffer[512]; int argcount = 0; va_start(ap); while((args[argcount++] = va_arg(ap, char *)) != (char *)NULL) ; va_end(ap); sprintf(buffer,format,args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9]); printf("%s\n",buffer); return(buffer); } ------------