- Joined
- Oct 2, 2022
- Messages
- 1
- Reaction score
- 0
I have C library functions that I wish to call in main using the command-line arguments argc and argv. I have not been successful yet, this is something I wish to learn; is someone able to help me fix my code to properly output the result of my atoi() for any int passed to the prompt?
Code:
#include <stdio.h>
#include <stdlib.h>
int ft_atoi(char *str)
{
int num;
int neg;
num = 0;
neg = 1;
while (*str >= 9 && *str <= 13 && *str == 32)
str++;
while (*str == '-' || *str == '+')
{
if (*str == '-')
neg *= -1;
str++;
}
while (*str > '0' && *str < '9')
{
num = num * 10 + (*str - '0');
str++;
}
return (num * neg);
}
int main(int arc, char **argv)
{
int j;
//int *p
j = atoi(argv[1]);
//*p = &j;
printf("%d", ft_atoi(j));
return (0);
// error: incompatible integer to pointer conversion (int to char *)
}