Article 6FP4K Unable to compile due to not able to find itoa() library header file.

Unable to compile due to not able to find itoa() library header file.

by
ajiten
from LinuxQuestions.org on (#6FP4K)
Have made code based on idea to check if the given command line input is integer, or not; and to change the character to integer, if passes the check.
The check is based on the idea here. But there are many warnings, and the inability to find the library (i.e., the header) file, containing the itoa() function.

Code:#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main (int argc, char **argv) {
char tmp[16]; //scanf("%s", tmp);
//////
int N=argc-1; printf("The size of array: %d\n", N); int arr[N];
for (int i=0; i<N; ++i) {
printf("%d i/p: %s<> strlen(argv[%d]): %zu <> strlen(itoa(atoi(argv[%d]))): %zu", i+1, argv[i+1], i+1, strlen(argv[i+1]), i+1, strlen(itoa(atoi(argv[i+1]))) );
if( strlen(argv[i+1]) == strlen(itoa(atoi(argv[i+1]))) )
arr[i]= atoi(argv[i+1]);
}
printf("\n The %d values:", N);
for (int i=0; i<N; ++i) {
printf("\n:%d i-th <> %d", i, arr[i]);
}
}Compilation errors:
Code:main.c: In function imaini:
main.c:9:143: warning: implicit declaration of function iitoai [-Wimplicit-function-declaration]
9 | printf("%d i/p: %s<> strlen(argv[%d]): %zu <> strlen(itoa(atoi(argv[%d]))): %zu", i+1, argv[i+1], i+1, strlen(argv[i+1]), i+1, strlen(itoa(atoi(argv[i+1]))) );
| ^~~~
main.c:9:143: warning: passing argument 1 of istrleni makes pointer from integer without a cast [-Wint-conversion]
9 | printf("%d i/p: %s<> strlen(argv[%d]): %zu <> strlen(itoa(atoi(argv[%d]))): %zu", i+1, argv[i+1], i+1, strlen(argv[i+1]), i+1, strlen(itoa(atoi(argv[i+1]))) );
| ^~~~~~~~~~~~~~~~~~~~~
| |
| int
In file included from main.c:2:
/usr/include/string.h:407:35: note: expected iconst char *i but argument is of type iinti
407 | extern size_t strlen (const char *__s)
| ~~~~~~~~~~~~^~~
main.c:10:41: warning: passing argument 1 of istrleni makes pointer from integer without a cast [-Wint-conversion]
10 | if( strlen(argv[i+1]) == strlen(itoa(atoi(argv[i+1]))) )
| ^~~~~~~~~~~~~~~~~~~~~
| |
| int
In file included from main.c:2:
/usr/include/string.h:407:35: note: expected iconst char *i but argument is of type iinti
407 | extern size_t strlen (const char *__s)
| ~~~~~~~~~~~~^~~
/usr/bin/ld: /tmp/cc4yG4G0.o: in function `main':
main.c:(.text+0x144): undefined reference to `itoa'
/usr/bin/ld: main.c:(.text+0x222): undefined reference to `itoa'
collect2: error: ld returned 1 exit status
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments