Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Throwing errors when trying to compile code with ltoa in Linux

Tags:

c

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.

like image 529
Maddy Avatar asked Feb 04 '26 04:02

Maddy


1 Answers

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.

like image 128
Alok Save Avatar answered Feb 05 '26 21:02

Alok Save