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