Comparison between pointer and integer in C

后端 未结 8 1305
盖世英雄少女心
盖世英雄少女心 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:13

    NULL is defined as a pointer type, usually (void*)0. This means it should not be compared to characters (which are promoted to integers when used on their own). The problem is with the following: str[i] != NULL. The correct way to do this is compare it to something of the same type, in this case you are looking for the null character, '\0'.

提交回复
热议问题