Sunday, July 12, 2009

How can i usee " itoa " function of standard library in C++ ????

i dont know how to use it n wats the syntex .............





if Y is some integer and i want to put its value in char Z ....by using itoa function ....how will i do it and also what is that 3rd argument (ie an int) in that function plzzzzzzzzzzzzz help mee

How can i usee " itoa " function of standard library in C++ ????
It Converts an integer into a string. This is not ANSI C.





It defined in stdlib.h


syntax id : char *itoa( int value, char *string, int radix );


itoa converts the integer val into a string using radix as the base.





value


Is the integer to be converted to string representation.





string


Points to the buffer that is to hold resulting string. The resulting string may be as long as seventeen bytes.





radix


Is the base of the number; must be in the range 2 - 36.





itoa() is not in the standard C library.


it acts like strtol() with base 10.But, if the value of the


integer is outside the range of an int the behaviour is undefined.





strtol() and strtoul() are recommended instead of atoi(). You can also choose a base from 0 to 36. Open your C-book for detail.











If you want to convert integer Y to a char Z then try








char *z = itoa( y, char *str, 10);





I assumed here you are converting a number of base10.





this function returns the string str.. and that we are storing in z.





Hope you understood.
Reply:The first parameter is the integer. The second is the char*. The third parameter is the maximum length of the char string. E.g.





itoa(nInt, szBuf, sizeof(szBuf));


No comments:

Post a Comment