linux下c语言gotoxy()实现代码,怎么这么神奇

lsjfdjoijvtghu 2014-01-06 06:16:56
void gotoxy(int x,int y)   //Fantasy  
{
printf("%c[%d;%df",0x1B,y,x);
}

想不通啊,c语言白学了,这里面是正则表达式吗?怎么会有移动光标效果的?
...全文
378 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
大奶兔白糖 2014-01-07
  • 打赏
  • 举报
回复
学习了
图灵狗 2014-01-07
  • 打赏
  • 举报
回复
++
引用 3 楼 KenZhang1031 的回复:
ANSI转义序列,很多类unix的终端,包括linux控制台都解释ANSI转义序列,转义符就是ESC,ASCII码是0x1b,比如
Esc[Line;Columnf
就表示移动光标到(Line,Column)的位置。而你printf打印的字符串正是这个命令,其中0x1B正是 ESC的ASCII码。
赵4老师 2014-01-07
  • 打赏
  • 举报
回复
In the following list of ANSI escape sequences, the abbreviation ESC represents the ASCII escape character 27 (1Bh), which appears at the beginning of each escape sequence. ESC[PL;PcH Cursor Position: Moves the cursor to the specified position (coordinates). If you do not specify a position, the cursor moves to the home position--the upper-left corner of the screen (line 0, column 0). This escape sequence works the same way as the following Cursor Position escape sequence. ESC[PL;Pcf Cursor Position: Works the same way as the preceding Cursor Position escape sequence. ESC[PnA Cursor Up: Moves the cursor up by the specified number of lines without changing columns. If the cursor is already on the top line, ANSI.SYS ignores this sequence. ESC[PnB Cursor Down: Moves the cursor down by the specified number of lines without changing columns. If the cursor is already on the bottom line, ANSI.SYS ignores this sequence. ESC[PnC Cursor Forward: Moves the cursor forward by the specified number of columns without changing lines. If the cursor is already in the rightmost column, ANSI.SYS ignores this sequence. ESC[PnD Cursor Backward: Moves the cursor back by the specified number of columns without changing lines. If the cursor is already in the leftmost column, ANSI.SYS ignores this sequence. ESC[s Save Cursor Position: Saves the current cursor position. You can move the cursor to the saved cursor position by using the Restore Cursor Position sequence. ESC[u Restore Cursor Position: Returns the cursor to the position stored by the Save Cursor Position sequence. ESC[2J Erase Display: Clears the screen and moves the cursor to the home position (line 0, column 0). ESC[K Erase Line: Clears all characters from the cursor position to the end of the line (including the character at the cursor position). ESC[Ps;...;Psm Set Graphics Mode: Calls the graphics functions specified by the following values. These specified functions remain active until the next occurrence of this escape sequence. Graphics mode changes the colors and attributes of text (such as bold and underline) displayed on the screen. ……
Mr. Code 2014-01-06
  • 打赏
  • 举报
回复
ANSI转义序列,很多类unix的终端,包括linux控制台都解释ANSI转义序列,转义符就是ESC,ASCII码是0x1b,比如
Esc[Line;Columnf
就表示移动光标到(Line,Column)的位置。而你printf打印的字符串正是这个命令,其中0x1B正是 ESC的ASCII码。
ooolinux 2014-01-06
  • 打赏
  • 举报
回复
不懂,mark。
angel_su 2014-01-06
  • 打赏
  • 举报
回复
只是特定控制台下,这串字会被视为光标命令,同c还是printf关系不大...

69,337

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧