[CODE] Useful Function

From: Ground Zero Enterprises (zero@baker.cnw.com)
Date: 10/05/96


This is a little function I wrote so OasisOLC would be able to save 
bitvectors as letters not numbers and it has been working well for me.
If you want to use it with OasisOLC:

put this fucntion somewhere in olc.c:

void bits_to_ascii(long flag, char *string)
{
  bool set = FALSE;
  register int i;
  char letter[2] = {'a'};
  char bits[40] = {'\0'};

  strcpy(string, "0");

  for (i = 0; i < 32; i++) {
    if (i == 26)
      *letter -= 58;
    if (IS_SET(flag, (1 << i))) {
      set = TRUE;
      strcat(bits, letter);
    }
    ++*letter;
  }

  if (set)
    strcpy(string, bits);
}

prototype it where it says 'from olc.c' in olc.h as:

bits_to_ascii(long flag, char *string);

then in the ?edit_save_to_disk fucntions anytime it wants to write a 
bitvector make sure there is a variable like:

char bits[40];

and where it intializes other strings that need to be wrote do:

bits_to_ascii(GET_BLAH(blah), bits);

and in the fprintf or sprintf change the %d that was for the bitvector to 
a %s, then replace the bitvector with bits and it should work.

Hope it helps someone.

Chris


+-----------------------------------------------------------+
| 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/18/00 PST