The Who List

Posted by Malti on Tue 02 May 2006 01:29 AM — 4 posts, 15,405 views.

USA #0
I have been on several MUDs (good ones are hard to find these days) and I have realized that many of them have formatted who lists. What I mean by this is that everything is spaced nicely. I decided I want to do the same thing, but I am stuck...

I want this format

[ lvl Class ] Name Title and all that other info
[ lvl Class ] Name Title and all that other info

There is a problem in the fact that the classes and level strings can be different lengths. I have changed the following.

snprintf( class_text, MAX_INPUT_LENGTH, "[  %s%2d %s   ]", NOT_AUTHED( wch ) ? "N" : " ", wch->level,
                class_table[wch->Class]->who_name );


This generates what I want, except it is based off of how long the class and level strings are. Is there a way I can make it a standard length so no matter what class, race, etc. it will all be uniformed with the braces?



USA #1
You can use %10s to format all strings as width 10, but that'll use more than you need. What you might have to do to get it "right" is to store all your lines in memory, and then count the widest one; once you have that widest entry, you can format everything to that width.
USA #2
Yes, you would use formatting. I'm trying to think of the man page. I think it's one of the printf pages... I'm not sure. An example would be using %5s, %-5s, and so on.
USA #3
[ %s%2d %-10s ] 


I used that and It works prefectly. Thanks very much for your help!