I have noticed that when you try to print a null character in C, nothing will get printed.
printf("trying to print null\n");
printf("%c", '\0');
However, I am trying to print the characters in the following array one by one, up to the sixth character which is the null character.
char s[] = "Hello\0Bye";
int i;
for(i = 0; i < 7; i++) {
printf("%c", s[i]);
}
printf("\n");
I was expecting "Hello" to be printed, as since the sixth character is null nothing will be printed. However my output was: "HelloB". It seems like printf skipped the null character and just went to the next character. I am not sure why the output is "HelloB" instead of "Hello".
Any insights would be really appreciated.
6? Draw out the string on a squared paper, one character per square, and count if you're unsure.sed 's/\x0/\n/g', see what gets printed.