Question:
how can i usee " itoa " function of standard library in C++ ????
2006-11-21 11:18:45 UTC
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
Three answers:
ramacrishna
2006-11-21 12:23:26 UTC
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.
jacinablackbox
2006-11-21 11:46:23 UTC
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));
Gladys
2016-03-29 08:26:48 UTC
Hi! Definition: The function strncmp compares characters of two strings. Example: #include #include #include void main(int argc, char *argv[]) { if(argc != 3){ printf("Incorrect number of parameters"); exit(1); } if(!strncmp(argv[1], argv[2], 8)) /* Compare 8 chars */ printf("Same name os files!"); }


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...