Ok this is half a little snippet and half a suggestions e-mail. I have
two handy functions called send_to_char_centered() and divide.
Send_to_char_centered() will center a string of text to a screen 80
spaces wide, while divide will use stcc to make a divider. The syntax for
send_to_char_centered is: send_to_char_centered( "Hello world!", ch );
And for divide it's: divide( 40, ch ); This will make:
----------------------------------------
The code for the two are right here. So far I havn't found any bugs
except if you try to go over 78 '---'s in divide it will crash the MUD. I
just know SOMETHING has to be more wrong than that. Any suggestions for
improvement guys? Here's the code (Yes it's in semi-C++ for now):
/**********************************************************************
File: Util.cpp Description: Various text manipulation utilities
Author: Devin Torres Date: March 20, 2002
**********************************************************************/
/**********************************************************************
Needed includes.
**********************************************************************/
#include <cstdio>
#include <ctime>
#include <string>
#include "merc.h"
/**********************************************************************
Center a string of text.
**********************************************************************/
void send_to_char_centered( char *txt, CHAR_DATA *ch )
{
char buf[MAX_STRING_LENGTH];
short int length;
buf[0] = '\0';
length = strlen( txt );
if ( length > 78 )
length = 78;
if ( length < 1 )
length = 1;
length /= 2;
length = 40 - length;
do
{
strcat( buf, " " );
length--;
} while ( length != 0 );
strcat( buf, txt );
send_to_char( buf, ch );
}
/**********************************************************************
Build a centered divider for text.
**********************************************************************/
void divide( short int length, CHAR_DATA *ch )
{
char buf[MAX_STRING_LENGTH];
buf[0] = '\0';
if ( length > 78 )
length = 78;
if ( length < 1 )
length = 1;
do
{
strcat( buf, "-" );
length--;
} while ( length != 0 );
send_to_char_centered( buf, ch );
}