Re: more code

From: n (n@narnia.mhv.net)
Date: 07/13/96


On Sat, 13 Jul 1996, Nick B wrote:

> ACMD(do_score)
> {  
>    struct time_info_data playing_time; 
>    struct time_info_data real_time_passed(time_t t2, time_t t1);
>    sprintf(buf, "%s                   Info for %s\r\n", buf, GET_NAME(ch));
>    sprinttype(GET_RACE(ch), pc_race_types, buf2); 
>    sprintf(buf, "%sRace: %s", buf, buf2);
>    sprinttype(GET_CLASS(ch), pc_class_types, buf2);
>    sprintf(buf, "%s                 Class: %s\r\n", buf, buf2);
>    sprintf(buf,"--------------------------------------------------\r\n");
>    sprintf(buf, "You are %d years old.", GET_AGE(ch));
> 
> When I execute the score command within the mud, it starts printing info on
> the screen starting at the GET_AGE line.  Why won't it print anything above it?
sprintf overwrites the variable you sprintf into...
you can get around that by sprintf'ing the original variable into the
beginning of itself, like you did... but the original first line
    sprintf(buf, "You are %d years old.", GET_AGE(ch));
does not... thus overwriting everything in the 'buf' buffer...
change it to
    sprintf(buf, "%sYou are %d years old.", buf, GET_AGE(ch));
and it should work...

--
n@narnia.mhv.net         narnio@phish.nether.net
breed@mhv.net            n@IRC and Narnio@MUD



This archive was generated by hypermail 2b30 : 12/07/00 PST