警告:指针和整数之间的比较在C [默认启用] [英] warning: comparison between pointer and integer [enabled by default] in c

查看:770
本文介绍了警告:指针和整数之间的比较在C [默认启用]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检查用户输入是否仅包含数字或没有。所以,我用下面的code:

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]

因为的argv [1] [I] 是一个整数, NULL 是一个指针。我怎样才能避免这样的警告?

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

推荐答案

NULL 是不一样的空终止符。您应该使用'\\ 0'代替。

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

这篇关于警告:指针和整数之间的比较在C [默认启用]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆