Beispiel #1
0
int str2int(char *str){

    //printf("%s\n", str);
    int tam = strlen(str);
    //printf("%d\n", tam);

    int sum = 0;

    int i;

    //printf("\n%d\n", tenPow(4));

    for(i = tam-1; i > 0; i--){
        //printf("%c %d %d\n", str[i], char2int(str[i]), tenPow(tam-1-i));//(tam-1-i)
        sum += (char2int(str[i]) * tenPow(tam-1-i));
    }


    if(str[i] == '-')
        sum *= -1;
    else
        sum += (char2int(str[i]) * tenPow(tam-1));

    //printf(">%d<\n", sum);

    return sum;
}
int tenPow(int num)
{
	if (num == 0)
		return 1;
	else
		return(10 * tenPow(num - 1));
}
int isGreater(char *date1, char* date2)
{
	int i, p = 0;
	int temp1 = 0, temp2 = 0, count = 1;
	//checking for year
	for (i = 9, p = 0; i >= 6; i--, p++)
	{
		temp1 += (date1[i] - '0') * tenPow(p);
		temp2 += (date2[i] - '0') * tenPow(p);
	}
	//printf("%d,%d", temp1,temp2);
	if (temp1>temp2)
		return 1;
	else if (temp1<temp2)
		return -1;
	else
	{
		//checking for month
		for (i = 4, p = temp1 = temp2 = 0; i >= 3; i--, p++)
		{
			temp1 += (date1[i] - '0') * tenPow(p);
			temp2 += (date2[i] - '0') * tenPow(p);
		}
		if (temp1>temp2)
			return 1;
		else if (temp1<temp2)
			return -1;
		else
		{
			//checking for date
			for (i = 1, p = temp1 = temp2 = 0; i >= 0; i--, p++)
			{
				temp1 += (date1[i] - '0') * tenPow(p);
				temp2 += (date2[i] - '0') * tenPow(p);
			}
			if (temp1>temp2)
				return 1;
			else if (temp1<temp2)
				return -1;
			else
				return 0;
		}
	}
}
Beispiel #4
0
int tenPow(int i){
    if(i == 0)
        return 1;
    else
        return 10 * tenPow(i-1);
}
int dateCheck(char *dateInput, int len,int *date,int *month,int *year)
{
	int flag, place;	
	for (place = 0, flag = len - 1; dateInput[flag] != '-'&&flag >= 0; flag--, place++)
	{
		(*year) += tenPow(place)*(dateInput[flag] - '0');
	}
	if (numofDig((*year)) != 4)
	{
		//puts("Invalid format");
		return(-1);
	}	
	for (place = 0, flag = flag - 1; dateInput[flag] != '-'&&flag >= 0; flag--, place++)
	{
		(*month) += tenPow(place)*(dateInput[flag] - '0');
	}
	if ((*month) <= 0 || (*month) > 12)
	{
		//puts("Invalid Date");
		return(-1);
	}
	for (place = 0, flag = flag - 1; dateInput[flag] != '-'&&flag >= 0; flag--, place++)
	{
		(*date) += tenPow(place)*(dateInput[flag] - '0');
	}
	switch ((*date))
	{
	case 0:
		//printf("Invalid Format");
		return(-1);
	case 31:
		if ((*month) == 4 || (*month) == 6 || ((*month) == 9) || ((*month) == 11))
		{
			//printf("Invalid Date");
			return(-1);
		}
	case 29:
		if ((*month) == 2)
		{
			if ((*year) % 100 == 0)
			{
				if ((*year) % 400 != 0)
				{
					//printf("Invalid Date");
					return(-1);
				}
			}
			else if ((*year) % 4 != 0)
			{
				//printf("Invalid Date");
				return(-1);
			}
	default:
		if ((*date) > 31)
		{
			//printf("Invalid Format");
			return(-1);
		}
		}
	}
	return 0;
}