Kay said:
how to convert int to char * ?
An integer type cannot be portably converted to a pointer.
Perhaps you want to create the textual representation of
an integer, e.g. "123" and have a 'char*' object point to it?
I have found this in a web site.
Which shows the danger of looking to 'a web site' for
accurate information. You should have at least one (preferably
two or more) books for learning C. See
www.accu.org for
peer reviews and recommendations. Also see the C FAQ:
http://www.eskimo.com/~scs/C-faq/top.html
and the comp.lang.c 'welcome message':
http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html
...both of which contain links to useful information about C.
However, it doesn't work even I change
itoa to atoi including stdlib.h
char str[10];
int i=567;
str=itoa(i, str, 10);
There is no function 'itoa()' in the C standard library
(though some implementations might provide such a function as an
extension). The C standard library does have a function
'atoi()', but it converts a the textual representation
of an integer to an integer.
You won't get far by just guessing and changing things
blindly, hoping it will work.
If you want to create the textual representation of an
integer, use 'sprintf()':
int i = 123; /* create an integer object */
char text[20]; /* create a place to store text */
sprintf("%d", text); /* create textual representation of 'i' */
/* and store it in the array 'text' */
char *p = text; /* create a pointer and assign it the address of */
/* the first character of the array 'text' */
Note that a pointer alone is not sufficient, you need an actual
place to store the characters (here, the array 'text').
-Mike