Hi folks,
this is my code. I'm passing a date string [MMDDYYYY](e.g., 01022000) to the function check periods. Now i send the date to sepdate function. This function should separate the dates. if i print the returned array, am getting wrong answer.

int *sepdate(char *date)
{
	long int dt;
	int *rdt=malloc(9);
	dt=atol(date);
	rdt[2]=dt % 10000;
	rdt[1]=dt / 10000;
	rdt[1] = rdt[1] % 100;
	rdt[0] = dt / 1000000;
	return rdt;
}

int checkperiods(char *sdt,char *edt)
{
	int *s=malloc(9);
	int *e=malloc(9);
	int i;
	s=sepdate(sdt);
	e=sepdate(edt);
	for (i=0;i<3;i++)
		printf("%d\n ",s[i]);

	/*if(s[2]>e[2])
	
		return 0;
	
	else if(s[2]==e[2])
	{
		if(s[0]>e[0])
		
			return 0;
		
		if(s[0]==e[0])
			if(s[1]>e[1])
			
				
				return 0;
			
			else
				return 1;
		else
			return 1;
	}
	else
		return 1;*/
	return 1;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.