Ejemplo n.º 1
0
char* u64toa(uint64_t val, t_u64toa* str)
{
	#define BASE (10ull) /* Base10 by default */
	uint64_t sum;
	int pos;
	int digit;
	int max_len;
	char* res;

	sum = val;
	max_len = U64TOA_MAX_DIGIT;
	pos = 0;

	do
	{
		digit = (sum % BASE);
		str->data[pos] = digit + '0';
		pos++;

		sum /= BASE;
	}while( (sum>0) && (pos < max_len) );

	if( (pos == max_len) && (sum>0) )
		return NULL;

	str->data[pos] = '\0';
	res = stringrev(str->data);

	return res;
}
int main(int argc, char* argv[])
{
	char b[100],a[100];
	int b1=atoi(argv[1]); // b1 is the initial base of the number
	int b2=atoi(argv[2]);  // b1 is the final base of the number
							// This is the number to be converted
							// we have given the input as a number(base) and a string
	if(check(b1,argv[3])==1)
	{
		convert1(b1,b2,argv[3],b);
		stringrev(b);
		printf("%s\n",b);
	}
	else 
	printf("0\n");

}