Beispiel #1
0
int pow_ten(int idx)
{
	if (idx == 0) 
		return 1;
	else 
		return 10 * pow_ten(idx - 1);
}
Beispiel #2
0
void	ft_putnbr(int nb)
{
	int		k;
	long	nb1;

	nb1 = nb;
	k = pow_ten(nb1);
	if (nb1 < 0)
	{
		nb1 = ~(nb1) + 1;
		ft_putchar('-');
	}
	while (k != 0)
	{
		ft_putchar('0' + nb1 / k % 10);
		k = k / 10;
	}
}
Beispiel #3
0
uint32_t atoi_n(char * str, uint8_t n)
{
	uint32_t tmp = 0;
    uint8_t i;

	for (i=0; i < n; i++)
	{
		if (str[i] == ',')
			return tmp;
		if (str[i] == '.')
		{
			n++;
			continue;
		}

		tmp += (uint32_t)(str[i] - '0') * pow_ten(n - i - 1);
	}

	return tmp;
}
Beispiel #4
0
int main(int argc, char *argv[])
{
	if(argc != 2) {
		printf("Usage: ./QsortC <powerOfTen>\n");
		return 0;
	}
	int idx = atoi(argv[1]);
	int SIZE = pow_ten(idx);
	int *a = malloc(SIZE * sizeof(int));
	
	char inputFile[FNAME_SIZE];
	//char outputFile[FNAME_SIZE + 7];
	sprintf(inputFile, "%s%d%s", "10e",idx, ".txt");
	//sprintf(outputFile, "%s%d%s","10e",idx, "sortedC.txt");
		
	array_init(a, inputFile);
	quicksort(a, 0, SIZE - 1);
	printf("Quicksorted %d ints in C\n",SIZE);
	//Used to test sorting
	//array_print(a, outputFile, SIZE);
	free(a);
	return 0;
}