LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-18-2023, 12:35 PM   #1
ajiten
Member
 
Registered: Jun 2023
Posts: 377

Rep: Reputation: 4
Unable to compile due to not able to find itoa() library header file.


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 ‘main’:
main.c:9:143: warning: implicit declaration of function ‘itoa’ [-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 ‘strlen’ 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 ‘const char *’ but argument is of type ‘int’
  407 | extern size_t strlen (const char *__s)
      |                       ~~~~~~~~~~~~^~~
main.c:10:41: warning: passing argument 1 of ‘strlen’ 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 ‘const char *’ but argument is of type ‘int’
  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
 
Old 10-18-2023, 01:32 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,874
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Really impressive, but what you need is `strtol`
 
Old 10-18-2023, 02:07 PM   #3
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,146
Blog Entries: 6

Rep: Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834Reputation: 1834
https://stackoverflow.com/questions/...ction-in-linux
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot get past GDISK- Caution: Invalid backup GPT header, but valid main header, regenerating backup header from main header. murde Linux - Newbie 2 05-30-2020 08:23 PM
itoa hai12345 Linux - Software 5 06-30-2008 01:08 AM
GCC isn't detecting exit() and itoa()! Kixdemp Programming 3 03-12-2006 09:34 PM
Can't find itoa() russoue Programming 2 12-07-2004 12:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration