Re: was Exp Tester Program- Snippet?

angus@EDGIL.CCMAIL.COMPUSERVE.COM
Date: 07/11/97


     Quote ------>>>>
On Thu, 10 Jul 1997 13:37:09 -0500you wrote:

>> Also, if I want the program to be considered for the snippet sites and
>> stuff, who should I send it to, or should I send it to the list?
>>
>Just send it to the list.  I tend to grok stuff that looks interesting and
>has nothing to do with Oasis or OBuild. (=
>
Why, whats wrong with OBuild and Oasis??
     <<<<------ Quote


     ------
     I think they have their own www archives of patches.  I know Sam does,
     and the other one should.

     Would this work for a snippet? :)

     just a little bite of code for those of you who HAVE to be sure a
     string is a certain length (the printf modifiers can screw things up
     some times with over/under runs.)


/*
   adds spaces to the end of strings so that you can be sure what length
they
   will be.  First used to make the score command come out correctly
   takes in the string to alter and the total number of spaces the string
   should take up, puts out (in source) a string of length total_length
   ending with a \0
   masque 3/11/95
*/
void str_add_spaces(char *source,int total_length)
{
   char *string = source;
   int i=0;

   /* work along the string until end of string or == desired length */
   while((total_length>=i)&&(*string!='\0'))
      {
      *string++;
      i++;
      }


   /* Add spaces to make sure length is correct */
   for(;i<=total_length;i++)
      {
      *string=' ';
      *string++;
      }

   /* end the string */
   *string='\0';
}



     I might have missed something in printf, but I really really really
     wanted to be sure things were spaced as I wanted them.  We save titles
     and have changed the score command to print out into a box of '*'s.
     The problem was, sometimes the titles would be so long they would wrap
     around and mess up the box.  This was my solution for the problem.
     The best part is, I don't think it leaks memory and i think it is as
     tight as i can get it!!! =)  is there a way to FORCE sprintf to
     truncate a string if it gets too long, AND add spaces to the end of a
     string if it is too short? and is this faster then using 2 sprintf's?
     One to insert the %d's, %f's into the string, and the second to
     correctly position the string?  this is an implementation of this
     code:

sprintf(buf_temp1,"%s",cur->cl_players[0]);
str_add_spaces(buf_temp1,12);
sprintf(buf_temp2,"%s",cur->cl_name);
str_add_spaces(buf_temp2,13);
sprintf(buf_temp3,"%d",cur->cl_room);
str_add_spaces(buf_temp3,9);
sprintf(buf_temp4,"%d",cur->cl_number);
str_add_spaces(buf_temp4,12);
sprintf (send,"| %s| %s| %s| %s|\n\r",buf_temp1,buf_temp2,buf_temp3,buf_temp4);
send_to_char(send,ch);

send_to_char("-----------------------------------------------------------\n\r",c
h);


     could just strcat into "send" for each one, but this looks faster even
     if it uses more memory.


      +-----------------------------------------------------------+
      | Ensure that you have read the CircleMUD Mailing List FAQ: |
      |   http://cspo.queensu.ca/~fletcher/Circle/list-faq.html   |
      +-----------------------------------------------------------+



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