Please take a look on this...
Code:
#include <stdlib.h> //malloc, free, itoa
#include <stdio.h> //printf
#define POSSIBLE_MAXIMUM_INT_VALUE 10
char *IntToStr(int value)
{
char *buffer = malloc(POSSIBLE_MAXIMUM_INT_VALUE);
itoa(value, buffer, 10);
// ^-- base 10
return buffer;
}
int main()
{
int value = 2008;
printf("%s\n", IntToStr(value)); // >> 2008
//Question: Should we deallocate the returned value?
//do we need to get the buffer first??
//get the returned value
char *buffer = IntToStr(value);
//do something with buffer
printf("%s\n", buffer); // >> 2008
//deallocate the buffer
free(buffer);
}
Thanks in advance V(^_^)V