wrap_string.txt
snippets · 804 B · 2010-03-30
wrap_string: returns a string with line returns inserted (from the RomList, credited to Fallon).
Download « Back to the snippets list
Extracted from the RomList:
---------------------------
Hi gang,
From my db.c:
/* Returns a string with returns inserted - Fallon */
char *wrapstr( CHAR_DATA *ch, const char *str )
{
static char strwrap[MAX_STRING_LENGTH];
int i;
int count = strlen(IS_NPC(ch) ? ch->short_descr : ch->name);
for ( i = 0; i < strlen(str); i++ )
{
count++;
if ( count > 66 && str[i] == ' ' )
{
strwrap[i] = '\n';
strwrap[i+1] = '\r';
count = 0;
}
else
{
strwrap[i] = str[i];
}
}
strwrap[i] = '\0';
return strwrap;
}
The above is what I use to wrap strings to under 80 characters in
do_say. All the other similar code I've seen has been a LOT longer.
Am I pulling some stupid trick here? It seems to work fine.
Sincerely,
Sandi
mailto:sandif@townisp.com
telnet: blades.inetsolve.com 3333