LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   A question about atoi() i C... (https://www.linuxquestions.org/questions/programming-9/a-question-about-atoi-i-c-4175450363/)

trist007 02-15-2013 06:31 PM

A question about atoi() i C...
 
I'm trying to understand why I get this error when I compile
functions.c:521: warning: passing argument 2 of 'AddRecord' makes pointer from integer without a cast
arg2 is a char pointer already why is it complaining?
Code:

char *arg1;
        char *arg2;
        char *arg3;
        char *arg4;

        arg1 = strtok(args, " ");
        arg2 = strtok(NULL, " ");
        arg3 = strtok(NULL, " ");
        arg4 = strtok(NULL, " ");

Code:

if (strncmp(arg1, "add", 1) == 0) {
                if (arg4 == NULL)
                        AddRecord(conn, NULL, arg2, arg3);
                else
                        AddRecord(conn, atoi(arg2), arg3, arg4);  // line 521
                DatabaseWrite(conn, filename);
}


j13ett5 02-15-2013 06:52 PM

It's complaining because atoi converts char-pointer into an integer represention of what it finds at the poited-to location.

Drop the atoi

AddRecord(conn, arg2, arg3, arg4); // line 521

trist007 02-15-2013 10:01 PM

Ah ok yes I see now. Thanks.


All times are GMT -5. The time now is 01:38 PM.