If you look at the output of your terminal, you do not know if your program is running that does not behave as expected, or maybe just your terminal emulator.
On UNIXoid systems, use ./myProgram | hexdump -C ./myProgram | hexdump -C to see hex output. This way, you will make sure that your program does what you expect from it, so that a terminal that does not behave as expected:
00000000 30 0a 00 0a |0...| 00000004
If you see the same result as me, you are actually printing zero '0' , new line '\n' , null '\0' , new line '\n' . Thus, in this case, your program behaves as you expected.
You might want to try various terminal emulators or settings.
source share