home *** CD-ROM | disk | FTP | other *** search
- /* intascii.c */
- /* */
- /* Very trivial but useful: converts an unsigned integer into an ASCII */
- /* string of the given lenght that can be used by the Text() function */
-
- char *intascii(number, string, lenght)
- unsigned int number;
- char string[];
- int lenght;
- {
- int i, c, j;
- char *oldstring = "000000";
- int difference;
-
- i = 0;
-
- do
- string[i++] = number % 10 + '0';
- while((number /= 10)> 0);
- string[i] = '\0';
-
- for(i = 0, j = strlen(string) -1; i < j; i++, j--)
- {
- c = string[i];
- string[i] = string[j];
- string[j] = c;
- }
-
- if(strlen(string) < lenght)
- {
- difference = lenght - strlen(string);
-
- for (i = 0; i < difference; i++)
- oldstring[i] = '0';
- j = 0;
- while((oldstring[i++] = string[j++]) != '\0')
- ;
- }
- else
- oldstring = string;
- return(oldstring);
- }
-