How do I print the null terminator in C?
1 min readMar 11, 2020
I was writing some code in C where I wanted to print out the null terminator for debugging reasons. This is often something that is needed if you’re checking that you’re performing some low-level string operations properly. Here is a “detailed_print” method which prints null terminators as “\0”:
void detailed_print(char str[], size_t size) {
for(size_t i = 0; i < size; i++) {
if (str[i] == '\0') {
fputs("\\0", stdout);
}
printf("%c", str[i]);
}
puts("");
}
That’s all for now, I hope this was as helpful to some of you as it was for me!