You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
487 B
C

24 years ago
#include "fmt.h"
size_t fmt_ulong(char *dest,unsigned long i) {
register unsigned long len,tmp,len2;
24 years ago
/* first count the number of bytes needed */
for (len=1, tmp=i; tmp>9; ++len) tmp/=10;
if (dest)
for (tmp=i, dest+=len, len2=len+1; --len2; tmp/=10)
*--dest = (char)((tmp%10)+'0');
24 years ago
return len;
}
#ifdef UNITTEST
#include <assert.h>
#include <string.h>
int main() {
char buf[100];
assert(fmt_ulong(buf,12345)==5 && !memcmp(buf,"12345",5));
return 0;
}
#endif