I have declared and initialized two variables as shown below:
int a=5;
char* str;
str = (char*)calloc(255, sizeof(char));
I want to convert the int to char* in standard C. I cannot use any conversion function from C++ such itoa.
I am using Ubuntu 11.10
First of all,
itoais not a C++ thing.You can simply use
sprintf:In a real application you’ll want to use
snprintfthough to remove the risk of a buffer overflow:And 15 characters are way enough to store an integer.