Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: comparison between pointer and integer [enabled by default] in c

I want to check whether the user input contains only digits or not. So, I use the following code:

for(i = 0; argv[1][i] != NULL; i++)
    if(!isdigit(argv[1][i]))
    {
        printf("Error");
        return -1;
    }

It works well but I got this warning:

warning: comparison between pointer and integer [enabled by default]

since argv[1][i] is an Integer and NULL is a pointer. How can I avoid such warning?

like image 238
Eng.Fouad Avatar asked Dec 03 '22 00:12

Eng.Fouad


1 Answers

NULL is not the same as the null-terminator character. You should use '\0' instead.

like image 171
Oliver Charlesworth Avatar answered Dec 04 '22 14:12

Oliver Charlesworth