How do I get printf to move to a tab position?

Duane L. Rezac cpp90221 at dcscg1.UUCP
Thu May 26 21:46:23 AEST 1988


In article <242 at tahoma.UUCP>, jwf0978 at tahoma.UUCP (John W. Fawcett) writes:
> ....  I would like to be able to tab over to a certain
> position on a line and place some text there without overwriting text that
> was already on the line.....

 
NOTE: our posting program indicated that my original attempt at posting
      this may not have made it out, so I am posting it with a diffrent
      program. If this is a duplicate posting, my appologies.


I am a newcomer to C, just finishing my first class in C, but this may help.


If you are using an ansi terminal, this code may help.  I wrote this printl
function in order to let me print to a specific screen position. If you are
trying to print to a printer, you could replace the ansi cursor movement 
statement with the appropriate command sequence for your printer.
(If someone knows a better way to do this, Please post it. As I said, I am 
 a novice at C and there may be better ways to do this.)

/* printl - print at location x,y  x,y = screen position,
            control=printf template,
             args=data to be printed

            This is used just like printf except that an x,y screen position
            is passsed. (i.e. printl(10,10,"%s",name) prints the string name
            at column 10, row 10)*/
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 */
}

I hope this helps.



More information about the Comp.lang.c mailing list