01 Feb, 2010, Bojack wrote in the 21st comment:
Votes: 0
K I messed with it a bit more and now it shows this:
Loner strlength 5
Frozen Empire strlength 13
Universal Defense Force strlength 23

[ Loner ]
[ Frozen Empire ]
[Universal Defense Force]
[ newtest ]


Well for some reason it aint lining up on here right but in game it does so you get the idea.

Edit by kiasyn: code tags
01 Feb, 2010, David Haley wrote in the 22nd comment:
Votes: 0
You would need to use the code tags for it to line up properly here.
01 Feb, 2010, Crelin wrote in the 23rd comment:
Votes: 0
heh, well I got it working…coded it my way a bit though…finished product…
char * center_string(char * str, int width)
{
static char result[MSL];
int length = colorstrlen(str);

if (length >= width)
return str;

int tspace = (width-length);
int lspace = (tspace/2);
int rspace = (tspace/2);

if ((rspace * 2) < tspace)
rspace++;

sprintf(result,"%*s%s%*s",lspace,"",str,rspace,"");
return result;
}


and used the colorstrlen code bojack posted since my rom didn't have one.

Thank you everyone for the help

Edit: actually running into a problem I'm trying to fix now
01 Feb, 2010, Crelin wrote in the 24th comment:
Votes: 0
well the problem I'm getting now is that I call center_string for both whotitle and clanname in do_who - (only shows whotitle version if you have one set) - but when I set one…it showed both clanname and whotitle as the whostring (changed do_who slightly and now it shows both as the clanname)…modified my center_string code to this:
const char* center_string(const char* str, int width)
{
static char result[MSL];
int length = colorstrlen(str);

if (length >= width)
return str;

int tspace = (width-length);
int lspace = (tspace/2);
int rspace = (tspace/2);

if ((rspace * 2) < tspace)
rspace++;

sprintf(result,"%*s%s%*s",lspace,"",str,rspace,"");
return result;
}


and I get the warning: string.c:747: warning: passing argument 1 of colorstrlen discards qualifiers from pointer target type which is this line:
int length = colorstrlen(str);


Here's the section of code from my do_who function
if (wch->pcdata->whotitle[0] != '\0')
{
sprintf( buf, "{D[{x%s{D]{x [%s] %s %s %s%s%s%s%s%s%s\n\r",
whotitle,
clanname,
wch->name,
wch->lastname,
IS_NPC(wch) ? "" : wch->pcdata->title,
wch->incog_level >= LEVEL_HERO ? "(Incog) " : "",
wch->invis_level >= LEVEL_HERO ? "(Wizi) " : "",
wch->timer >= 10 ? "[IDLE]" : "",
IS_SET(wch->comm, COMM_AFK) ? "[AFK] " : "",
IS_SET(wch->act, PLR_KILLER) ? "(KILLER) " : "",
IS_SET(wch->act, PLR_THIEF) ? "(THIEF) " : "");
}


and the section of code that sets the whotitle and clanname variables:
char const *whotitle;
char const *clanname;

if (wch->pcdata->whotitle[0] != '\0')
whotitle = center_string(wch->pcdata->whotitle,16);
else
whotitle = center_string("NULL",16);

if (wch->clan)
clanname = center_string(clan_table[wch->clan].who_name,23);
else
clanname = center_string("Adventurer",23);


any ideas?
01 Feb, 2010, Crelin wrote in the 25th comment:
Votes: 0
alright, I fixed it - changed my code in do_who to set the variables like this:
if (wch->pcdata->whotitle[0] != '\0')
sprintf(whotitle,"%s",center_string(wch->pcdata->whotitle,16));
else
sprintf(whotitle,"%s",center_string("NULL",16));

if (wch->clan)
sprintf(clanname,"%s",center_string(clan_table[wch->clan].who_name,23));
else
sprintf(clanname,"%s",center_string("Adventurer",23));


I still have the
string.c: In function center_string:
string.c:747: warning: passing argument 1 of colorstrlen discards qualifiers from pointer target type
code warning though.
01 Feb, 2010, kiasyn wrote in the 26th comment:
Votes: 0
you will also need to declare whotitle, etc differently eg:
char whotitle[1024];


the reason it was showing them both as the same is that your whotitle and clanname were declared as pointers, both pointing at the static string inside center_string
01 Feb, 2010, KaVir wrote in the 27th comment:
Votes: 0
The warning message tells you the exact problem - that argument 1 of the colorstrlen() call on line 747 is discarding the qualifier (i.e., the 'const') from str.

whotitle and clanname are pointers. Where are you storing the string produced by sprintf()?
01 Feb, 2010, Crelin wrote in the 28th comment:
Votes: 0
yeah, forgot to include the declare code change too…I ended up declaring them as char whotitle[MSL] and char clanname[MSL].

as for the warning, you mean where am I storing the result string? that center_string produces?
01 Feb, 2010, David Haley wrote in the 29th comment:
Votes: 0
The result string of sprintf is the string at the beginning:

sprintf(foo, "Hello %s", ch->name)

The warning seems to be telling you that foo is a const char* but you are using it as a char*, which is a problem. That's what KaVir is asking you: where are you putting the results of sprintf? Into a const char* or something else?
01 Feb, 2010, Crelin wrote in the 30th comment:
Votes: 0
yes, I know…in the center_string function the only sprintf I use has it's result string called…result… and it's stored as static char result [MSL]

the whole code is this:
char* center_string(const char* string, int width)
{
static char result[MSL];
int length = colorstrlen(string);

if (length >= width)
return string;

int tspace = (width-length);
int lspace = (tspace/2);
int rspace = (tspace/2);

if ((rspace * 2) < tspace)
rspace++;

sprintf(result,"%*s%s%*s",lspace,"",string,rspace,"");
return result;
}


and the line the warning points to is
int length = colorstrlen(string);
01 Feb, 2010, Crelin wrote in the 31st comment:
Votes: 0
haha, doh, yeah…I was just confusing myself, changed the const char* string argument to just char* string - was a remnant from writing out code from earlier in the thread. :D

Funny thing is, could've swore I changed that last night and was getting other random weird warnings/errors and now compiles perfectly…tis what I get for coding until 5 in the morning on little sleep.
01 Feb, 2010, KaVir wrote in the 32nd comment:
Votes: 0
Crelin said:
as for the warning, you mean where am I storing the result string? that center_string produces?

I'm referring to your call to colorstrlen() - you're passing a "const char *" to a function which expects a "const *" argument. I would suggest adding the const type qualifier to colorstrlen().
20.0/32