www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/09/18:01:51

Date: Wed, 9 Apr 1997 17:44:28 -0400 (EDT)
From: "art s. kagel IFMX x2697" <kagel AT dg1 DOT bloomberg DOT com>
To: dabrownz AT mindspring DOT com
Cc: djgpp AT delorie DOT com
Subject: Re: Centering printf text on a 80 column screen
In-Reply-To: <334aed58.5263168@news.mindspring.com>
Message-Id: <Pine.D-G.3.91.970409173757.27668A-100000@dg1>
Mime-Version: 1.0

void center_print( char *mystring, short field_width )
{
    short center;

    center = ((1 + field_width) - strlen(mystring))/2;
    printf( "%*.*s%s\n", center, center, " ", mystring );
}

How's that?  The function will print any string centered in a 
'field_width' wide zone beginning at the current cursor position on the 
screen.  You can substitute fprintf, sprintf, or cprintf as needed.

Art S. Kagel, kagel AT ts1 DOT bloomberg DOT com

On Wed, 9 Apr 1997 dabrownz AT mindspring DOT com wrote:

> How do you center printf text on a DOS screen?  I can't find anyway to
> do this other than using tabs and spaces (very annoying).  What is the
> 'correct' way to do it?  Do I have to use 'cprintf' or some other
> keyword or include another library?  I'd would really appriciate any
> help, Thanks.
> 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019