www.pudn.com > iccavr_lib.rar > ltoa.c, change:2002-10-27,size:395b


#include <string.h> 
 
void ltoa(char *buf, unsigned long i, int base) 
	{ 
	char *s; 
#define LEN	25 
	int rem; 
	char rev[LEN+1]; 
 
	if (i == 0) 
		s = "0"; 
	else 
		{ 
		rev[LEN] = 0; 
		s = &rev[LEN]; 
		while (i) 
			{ 
			rem = i % base; 
			if (rem < 10) 
				*--s = rem + '0'; 
			else if (base == 16) 
				*--s = "abcdef"[rem - 10]; 
			i /= base; 
			} 
		} 
	strcpy(buf, s); 
	}