problem with writing intToString recursively

nil10000's Avatar, Join Date: Dec 2010
Newbie Member
Hi,
I'm trying to write a function that suppose to recieves a natural number and turn it into a string using a recursion, for example the number 123 will be {'1','2','3'}.
can someone please tell me why my code isn't working?


Code:
void intToStr(unsigned int num, char s[])
{
	if(num/10==0)
	{
		s[0]=(char)(num+48);
		s[1]='\0';
	}
	else
	{
		intToStr(num/10, s);
		s[strlen(s)]=(char)(num%10+48);
		s[strlen(s)+1]='\0';
	}
}

Last edited by shabbir; 2Jan2011 at 10:18.. Reason: Code blocks
nil10000's Avatar, Join Date: Dec 2010
Newbie Member
Never mind, I realized what I did wrong.