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
Post a Comment