Wrapper function to sprintf

Greg Hackney 214+464-2771 mechjgh at tness1.UUCP
Thu Mar 3 13:35:29 AEST 1988


In article <232400003 at prism> atj at 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 at tness1.UUCP

---------<cut here>---------

 #include <stdio.h>
 #include <varargs.h>
 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);

 }
-------<end of dippiness>-----



More information about the Comp.sys.pyramid mailing list