Re: [NEWBIE]Centering Lines

From: Glover, Rick I. (
Date: 05/13/00

-----Original Message-----
From: Cj
Sent: 5/12/00 9:20 PM
Subject: [CIRCLE] [NEWBIE]Centering Lines

What would be the best way of centering lines of text in a text editor?
If you wanted the same result(centered text) on the MUD?


You'd have to decide what to set as the width of everyone's screen that logs
onto your mud.  In most cases you will be wrong because of fonts, monitor
sizes and different telnet mud clients, but by just choosing something like
80 to be the default you can make a mathematical formula to determine the
number of spaces that you have to put before your string of text, such as:

spaces = (80 - strlen(mystring)) / 2;

and then create the line of text:

*buf = '\0';
for (i = 1; i <= spaces; i++)
  strcat(buf, " ");

sprintf(buf2, "%s%s\r\n", buf, mystring);

buf2 is now your centered line of text.  There is probably 5 different ways
you can do this, but this is probably the easiest to understand.

Later, you can probably add a variable to a character's saved information to
allow them to change the length of the lines on their screen and then have
your formula use that variable.

Best regards,

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

This archive was generated by hypermail 2b30 : 04/10/01 PDT