LMSouq
server-admin Open

Why does the terminal show "^[[A" "^[[B" "^[[C" "^[[D" when pressing the arrow keys in Ubuntu?

KE
Kevin Dong
1 month ago
3 views
Problem Description
I've written a tiny program in Ansi C on Windows first, and I compiled it on Ubuntu with the built-in GCC now. The program is simple: * read the line from console with `scanf()`. * Analyze the string and calculate. But something weird happens. When I try to move the cursor, it prints four characters: * pressing <kbd>Up</kbd> prints "`^[[A`" * pressing <kbd>Dn</kbd> prints "`^[[B`" * pressing <kbd>Rt</kbd> prints "`^[[C`" * pressing <kbd>Lt</kbd> prints "`^[[D`" ![](https://i.sstatic.net/kJOZP.png) * How can this be avoided? * Why does it print these 4 characters instead of moving the cursor?

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base