Print with command-line arguments

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 *)
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top