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++;
}
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 ;)