简体   繁体   中英

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?

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

argv [1] [i]是一个字符,只需将它与'\\ 0'或0进行比较,它就更清楚了。

对于字符比较,可以使用(或者只使用0);

for(i = 0; argv[1][i] != '\0'; i++)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM