home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d186 / cards'o'rama.lha / Cards'O'Rama / Sources / sources.zoo / intascii.c < prev    next >
C/C++ Source or Header  |  1989-02-25  |  1KB  |  43 lines

  1. /*                               intascii.c                             */
  2. /*                                                                      */
  3. /* Very trivial but useful: converts an unsigned integer into an ASCII  */
  4. /* string of the given lenght that can be used by the Text() function   */
  5.  
  6. char *intascii(number, string, lenght)
  7.    unsigned int number;
  8.    char string[];
  9.    int lenght;
  10.    {
  11.    int i, c, j;
  12.    char *oldstring = "000000";
  13.    int difference;
  14.  
  15.    i = 0;
  16.  
  17.    do
  18.       string[i++] = number % 10 + '0';
  19.    while((number /= 10)> 0);
  20.    string[i] = '\0';
  21.  
  22.    for(i = 0, j = strlen(string) -1; i < j; i++, j--)
  23.       {
  24.       c = string[i];
  25.       string[i] = string[j];
  26.       string[j] = c;
  27.       }
  28.  
  29.    if(strlen(string) < lenght)
  30.       {
  31.       difference = lenght - strlen(string);
  32.  
  33.       for (i = 0; i < difference; i++)
  34.          oldstring[i] = '0';
  35.       j = 0;
  36.       while((oldstring[i++] = string[j++]) != '\0')
  37.          ;
  38.       }
  39.    else
  40.       oldstring = string;
  41.    return(oldstring);
  42.    }
  43.