Re: Function for centering text

From: Gary Barnett (gbarnett@POLARNET.COM)
Date: 03/26/98

-----Original Message-----
From: Chris Hyde <slugger@CRYOGEN.FERRIS.EDU>
To: <>
Date: Thursday, March 26, 1998 7:48 PM
Subject:  Function for centering text

>Hello again =)
>I used the same formula that is used in the autowiz code, but it still
>will not work.  The autowiz uses a call to fputc(), and that requires as
>an argument a FILE stream to write to.  I tried using puts(), printf(),
>etc, and it still doesn't work(crashes with a seg fault).  I am trying to
>get it to work as a console program before incorporating it into my MUD
>code, but am having no luck.  Does anyone know of another way to write
>strings to the screen that I havent tried?  I realize that once
>incorporated, it will have to work with the send_to_char(), but I can
>tackle that later.


I won't comment on fputs, local console output or the rest. But.. for doing
this in the normal context of a CircleMUD I'll give a shot at it.

Seems to me you need to define the following variables and then you write a
routine to wrap around send_to_char.

1) Screen width (how wide is their screen.. 40/80/132?)

2) How wide is the line you are sending?

Given those two pieces of info, here's an approach using Mailer Code FWIW:


void send_to_char_centered(char *to_send, struct char_data *ch, shint
user_width) {
   shint spaces=0;
   shint line_width=0;
   char buf[MAX_STRING_LENGTH];

   if (*to_send)
      line_width = strlen(to_send);

   if ( (line_width > user_width)  ||
        (user_width <MIN_USER_SCREEN_WIDTH ) ||
        (line_width <1) )
      return; /* you can deal with these problems :-) */

   spaces = (user_width/2) - (line_width/2);

      buf[x] = ' ';

   strcat(buf, to_send);


     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | |

This archive was generated by hypermail 2b30 : 12/15/00 PST