On Thu, 26 Mar 1998, Chris Hyde wrote:
>Hello there...
> I am trying to write a function that will center a string of text
>in an 80 column display. I was wondering if anyone else has attempted
Here's a cut and paste for some code I wrote dealing with player formations.
This code centers the formation members's name in a field of 20 chars.
Just replace the twenty with 80 and it should work fine.
center = 20 - (strlen(GET_NAME(f->follower)));
if (center <= 0) {
sprintf(buf, "%s[%.20s]%s ", color, GET_NAME(f->follower), CCNRM(ch, C
_SPR));
break;
} else if (!(center % 2)) {
sprintf(buf, "%s[", color);
for (x = 0; x < center/2; x++)
sprintf(buf, "%s ", buf);
sprintf(buf, "%s%s", buf, GET_NAME(f->follower));
for (x = 0; x < center/2; x++)
sprintf(buf, "%s ", buf);
sprintf(buf, "%s]%s ", buf, CCNRM(ch, C_SPR));
break;
} else {
sprintf(buf, "%s[", color);
for (x = 0; x <= center/2; x++)
sprintf(buf, "%s ", buf);
sprintf(buf, "%s%s", buf, GET_NAME(f->follower));
for (x = 0; x < center/2; x++)
sprintf(buf, "%s ", buf);
sprintf(buf, "%s]%s ", buf, CCNRM(ch, C_SPR));
break;
}
Hmmm.. I must've written this a long time ago. It's probably much more
efficient to use strcat(buf, ' ') instead of sprintf(buf, "%s ", buf).
--
Hextall, Implementor of Exile * 888`98 9b.dP 888 888 888`98
exile.linex.com 4000 * 888+8, d8b 888 888 , 888+8,
The mud you've been looking for * 888,d8 d8 9b 888 888,d8 888,d8
+------------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
| http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
+------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/15/00 PST