You are actually using a line feed or new line character (β\nβ) instead of a carriage return (β\rβ). The short story is that you need this:
printf("Hello world\r\n");
Dating back to the era of typewriters, the line feed did just that; it literally fed a new line of paper into the typewriter. The carriage return also followed its namesake; it actually returned the carriage to the left most position, normally a duty done by physically sliding the carriage. Once the first printers appeared, the terminology carried over into computer science and C and sticks with us today.
By looking at the terminal windowβs output, the system is doing exactly what it was told to do; it added a new line (went down a line) but stayed at the same horizontal position where it was and continued to print (because the virtual carriage never returned to the left). Therefore, a β\rβ character should first return the printing position to the left most column before advancing to the next line with β\nβ. Does this make sense?