Warning: comparison between pointer and integer?

Hi, I wrote a loop to read from start to end of a char[] in C (see partial code below). I was taught that a null char == '\0' == NULL. However, my gcc compiler gave me a warning: comparison between pointer and integer. I don't understand why I have to use '\0' to replace NULL in the while loop to get rid of the warning. Any help, please?

1
2
3
4
5
6
7
8
  char buf[32];
  sprintf(buf, "%d", 234);

  while (buf[i] != NULL){
        tmp = buf[i] - '0';
        result += tmp;
        i++;
  }  
Last edited on
You are confusing two separate concepts. NULL is for pointers, whereas '\0' is for characters.
Interesting. I never realized that NULL is not the same for pointers as it is for characters ('\0') or for numbers (0).
At machine code level and assembly level they are usually always the same, but the whole point of a type system is to prevent you from mixing types accidentally ;)
Topic archived. No new replies allowed.