Comparison between pointer and integer in C

后端 未结 8 1311
盖世英雄少女心
盖世英雄少女心 2021-01-05 06:00

I have a bit stupid question about program in C. My compiler says me: warning: comparison between pointer and integer. I really don\'t know why. I only want to writ

8条回答
  •  不知归路
    2021-01-05 06:29

    NULL is a pointer and str[i] is the i-th char of the str array. char is and integer type, and as you compare them you get the warning.

    I guess you want to check for end of string, that would you do with a check for the char with the value 0 (end of string), that is '\0'.

    BUT: this wont help you as you define it just as and array of chars and not as a string, and you didnt define the termininating 0 in the char array (you get just lucky that it is implicit there).

    PS: Next time you should give at least the information where the compiler is complaining.

提交回复
热议问题