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 -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -