How do I get printf to move to a tab position?
Chris Torek
chris at mimsy.UUCP
Sun May 29 04:30:34 AEST 1988
In article <284 at dcscg1.UUCP> cpp90221 at dcscg1.UUCP (Duane L. Rezac) writes:
>(If someone knows a better way to do this, Please post it. ...
Okay:
>printl(x,y,control,args)
>unsigned char *control;
>unsigned args;
>int x,y;
>{
> printf("\33[%d;%dH",x,y); /* prints ansi cursor movement command to stdout*/
> printf(control,args); /* print data */
>}
x and y are actually used as row and column respectively; so this
should be `y, x' or `row, col'. In addition, you should use `vprintf'
if you have it, so as to have the correct types and number of arguments
at all times. Also, the control (format) argument should be `char *'.
#include <stdio.h>
#include <varargs.h>
int
#ifdef __STDC__
rcprint(int row, int col, char *fmt, ...) /* dpANS */
#else
rcprint(va_alist) /* K&R &/
va_dcl
#endif
{
int nchars;
va_list ap;
#ifndef __STDC__
int row, col; /* K&R */
char *fmt;
va_start(ap);
row = va_arg(ap, int);
col = va_arg(ap, int);
fmt = va_arg(ap, char *);
#else
va_start(ap, fmt); /* dpANS */
#endif
nchars = vprintf(fmt, ap); /* both */
va_end(ap);
return (ferror(stdout) ? EOF : nchars);
}
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list