A89: Re: Centering text with printf


[Prev][Next][Index][Thread]

A89: Re: Centering text with printf




Hi!

> I was looking through the documentation on TIGCCLIB 2.0, and I saw that
it's 
> possible to center text using printf, but the documentation isn't real
clear 
> on how to use it. I've tried various ways of trying to get it to center
the 
> text (such as printf("%|Center me") and printf("\|Center me") and 
> printf("Center me",|) ), but none work. Does anyone know how to implement

> this feature?

I know (of course)... Try this:

printf("%|26s","Center me");

Why? To understand this, you need to know more about formatting strings
(e.g. usage of format strings like "%10d" etc.). See, "|" is the formatting
flag option which tells that the appropriate argument will be centered in
the reserved space. 26 is the width of the reserved space in this case.
So, look the following:

printf("%s","Center me");    

prints just "Center me", because "%s" means "print the appropriate arg
as a string".

printf("%26s","Center me");

reserves a 26-character wide space, and prints the appropriate arg
("Center me") into this space, right alligned. Note that 26 is the
width of the screen if you use medium font size.

I hope that you now can guess the meaning of

printf("%|26s","Center me");

Cheers,

Zeljko Juric