1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

problem with writing intToString recursively

Discussion in 'C' started by nil10000, Dec 31, 2010.

  1. nil10000

    nil10000 New 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 a moderator: Jan 2, 2011
  2. nil10000

    nil10000 New Member

    Never mind, I realized what I did wrong.
     

Share This Page