#include <ctype.h>
#include "string_func.h"
#include "utility.h"

int atoint(const char *a)
{
	while (isspace(*a))
		a++;
	int sign = 1;
	if (*a == '-')
		sign = -1;
	if (*a == '+' || *a == '-')
		a++;
	int i = 0;
	while (isdigit(*a))
		i = *a++ - '0' + i*10;
	return sign*i;
}

char *inttoa(int i,char *a)
{
	char *p = a;
	do 
	{
		*a++ = i % 10 + '0';
	} while ((i /= 10) > 0);
	*a = '\0';
	return reverse(p);
}

double atofloat(const char *a)
{
	while (isspace(*a))
		a++;
	int sign = *a == '-' ? -1 : 1;
	if (*a == '+' || *a == '-')
		a++;
	double val = 0.0;
	while (isdigit(*a))
		val = *a++ - '0' + val * 10.0;
	if (*a == '.')
		a++;
	double power = 1.0;
	while (isdigit(*a))
	{
		val = *a++ - '0' + val * 10.0;
		power *= 10.0;
	}
	val = sign*val/power;
	if (*a == 'e' || *a == 'E')
		a++;
	sign = *a == '-' ? -1 : 1;
	if (*a == '+' || *a == '-')
		a++;
	int n = 0;
	while (isdigit(*a))
		n = *a++ - '0' + n * 10;
	if (sign == 1)
		while (n-- > 0)
			val *= 10.0;
	else
		while (n-- > 0)
			val /= 10.0;
	return val;
}



