TGViewer
Programming & AI Tips 💡 Programming & AI Tips 💡 @programmingtip · 46.3K subscribers
Post #273 1.36K
Difference between \n and \r 👀

In Unix and all Unix-like systems, \n is the code for end-of-line, \r means nothing special. 🤷🏻‍♂️

As a consequence, in C and most languages that somehow copy it (even remotely), \n is the standard escape sequence for end of line (translated to/from OS-specific sequences as needed)

in old Mac systems (pre-OS X), \r was the code for end-of-line instead. 🖥

As a (surprising) consequence (harking back to OSs much older than Windows), \r\n is the standard line-termination for text formats on the Internet. 🌏

For electromechanical teletype-like "terminals", \r commands the carriage to go back leftwards until it hits the leftmost stop (a slow operation), \n commands the roller to roll up one line (a much faster operation) — that's the reason you always have \r before \n, so that the roller can move while the carriage is still going leftwards!.

For character-mode terminals (typically emulating even-older printing ones as above), in raw mode, \r and \n act similarly (except both in terms of the cursor, as there is no carriage or roller) 😉

〰〰〰〰〰〰
#scape_secuence
@ProgrammingTip
More from @programmingtip
  1. Oct 7, 2026OpenAI Decisions API is in public beta 🚀 OpenAI's Decisions API is now in public beta. It…
  2. Oct 6, 2026Cloudflare shipped a Web Search API ⚡️ Cloudflare introduced a Web Search API. Search can…
  3. Oct 5, 2026AI is changing the developer career ladder 🚀 GitHub's latest developer career advice is r…
  4. Oct 2, 2026GPT-6 Astra gets an Ultrafast API tier 🚀 OpenAI added an Ultrafast speed tier for GPT-6 A…
  5. Oct 1, 2026Cloudflare shipped an agentic CLI for its API ⚡️ Cloudflare launched cf, an agentic CLI fo…
  6. Sep 30, 2026OpenAI introduced Dots, always-on agents 🚀 OpenAI introduced Dots, its take on always-on…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →