Q:

Throwing errors when trying to compile code with ltoa in Linux

I am getting compilation errors when i tried to compile the code as shown below
#include <stdlib.h>

main()
{
    int val = 10;
    char buff[10];
    char *ptr;
    ptr = ltoa(val,buff,10);
    printf("The val is %s\n",buff);
}

I get the compilation errors shown below:
[mcanj@varaprada ~]$ cc -g samp2.c
samp2.c: In function `main':
samp2.c:8: warning: assignment makes pointer from integer without a cast
samp2.c:11:2: warning: no newline at end of file
/tmp/ccifnKFx.o(.text+0x23): In function `main':
/home/mcanj/samp2.c:8: undefined reference to `ltoa'
collect2: ld returned 1 exit status.

Please let me know how to resolve this issue. Thanks and regards.

A:

It is itoa() and not ltoa() but even itoa() is not a Standard Library function.
If you want your program to be portable use sprintf() or snprintf() in C99.

A:

It's itoa, not ltoa. just change the call and it will be fine.

