954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Return integer array from a funtion

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;
}
infantheartlyje
Light Poster
29 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

sorry...Its working correctly.

infantheartlyje
Light Poster
29 posts since Jul 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: