c - Why I can't see that last char in array is null terminator? -


how can check char array null terminated?

char input[80];  fgets(input, sizeof(input), stdin);  (i = 0; input[i]; i++) {     if (input[i] == '\0') {        printf("null!!!"); // never works     } } 

for example, below code not print null.

in for loop condition, you're checking non-0 value of input[i], inside if dead condition.

to test, make infinite loop, check if , then, print , break out. like

for (i = 0; ; i++) {     if (input[i] == '\0') {        printf("null!!!\n");  // works        break;     } } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -