c - Why doesn't the printout of this program stop at the 0 digit? -


#include <stdio.h> #include <stdlib.h>  int main(int argc, char* argv[]) { char* key="844607587";   while(*key!=0){  printf("hello world,%c\n",*key);  key++;} } 

why doesn't program stop @ 0 digit? 0 mean? 1 without ' '

you made simple mistake - comparing (most ascii) characters in string numeric value 0. change:

while(*key!=0){ 

to

while(*key!='0'){ 

note numeric value 0 value of c string terminator, written '\0', code stops when reaches end of string, rather when sees character '0'.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -