问题

I was looking for a substitute of gotoxy() for gcc compiler and found this -

void gotoxy(int x,int y)

{

printf("%c[%d;%df",0x1B,y,x);

}

I want to know how is it functioning, I mean when do we use [ and ; inside printf, what is 0x1B doing there and how does it take the cursor to the row/column with this code?

I have never seen this type of practice for printf in books,so it would be great If you could point me to a link where I can find about such uses of printf.

回答1:

This is using terminal escape codes to position the cursor.

"\x1B" is the escape character that tells your terminal that what comes next is not meant to be printed on the screen, but rather a command to the terminal (or most likely terminal emulator)

The trailing 'f' indicates that you want to force the cursor position somewhere, indicated by the coordinates that precede it.

Force Cursor Position [{ROW};{COLUMN}f

So if you call gotoxy(4,2), it ends up sending the escape sequence "(ESC)[2;4f" where ESC is the byte 0x1B.

回答2:

These are called ANSI Escape Sequences and are derived from the DEC VT100 display terminal which was introduced in 1978.

回答3:

That is known as an ANSI escape code. I haven't seen those used in a while. Here's a page that explains about them:

http://en.wikipedia.org/wiki/ANSI_escape_code

来源:https://stackoverflow.com/questions/8683526/gotoxy-implementation-for-linux-using-printf

linux系统有gotoxy函数,gotoxy() implementation for Linux using printf相关推荐

  1. Linux系统中的函数

    Linux系统中的函数: 一.进程控制 fork 创建一个新进程 clone 按指定条件创建子进程 execve 运行可执行文件 exit 中止进程 _exit 立即中止当前进程 getdtables ...

  2. linux用Lseek函数 拷贝文件,linux系统下lseek函数的详细用法

    前面的文章里面,仔细讲了在linux系统对文件的读写操作以及文件管理,为今天要讲的内容作了铺垫(如果您是刚接触这方面的内容,可以先看我之前写的文章,有错误的地方,还望指出来,在这里先说一声谢谢).好了 ...

  3. linux系统线程通信的几种方式,Linux进程间通信-线程间通信

    Linux作为一种新兴的操作系统,几乎支持所有的Unix下常用的进程间通信方法:管道.消息队列.共享内存.信号量.套接口. 1.管道 管道( pipe ):管道是一种半双工的通信方式,数据只能单向流动 ...

  4. Linux系统详解 第五篇:Linux的安装-4:Fedora 16的安装

    Linux系统详解 第五篇:Linux的安装-4:Fedora 16的安装 前言: 本系列文章取材广泛,有来自于互联网的,有来自教科书的,有来自自己的笔记的,也有来自自己对Linux的经验积累的.此系 ...

  5. Linux系统运维与架构设计之Linux概述

    Linux系统运维与架构设计之Linux概述 Linux系统运维与架构设计 1.1 浅谈计算机系统 1.1.1 计算机硬件系统 现代计算机是基于冯·诺依曼体系结构,由运算器.控制器.存储器.输入设备. ...

  6. linux 文件和打印机共享文件夹,能实现Windows和Linux系统之间文件和打印机共享的Linux服务是( )...

    能实现Windows和Linux系统之间文件和打印机共享的Linux服务是( ) 答:SAMBA HTML 代 码 表示() 答:创建一个单选框 根据凯恩思的理论,在短期中总供给线为一条水平线,当总需 ...

  7. 61-20210407华为海思Hi3516DV300的linux系统下控制GPIO口(标准linux模式点亮LED灯)

    61-20210407华为海思Hi3516DV300的linux系统下控制GPIO口(标准linux模式点亮LED灯) 2021/4/7 15:13 https://xueqiu.com/797071 ...

  8. linux 如何运行函数,Linux系统中main函数的执行过程

    1. 问题:Linux如何执行main函数. 本文使用一个简单的C程序(simple.c)作为例子讲解.代码如下, intmain() { return(0); } 2.  编译 -#gcc -o s ...

  9. linux 系统时间是在哪里记录的,Linux系统如何记录时间

    1.内核在开机启动的时候会读取RTC硬件获取一个时间作为初始基准时间,这个基准时间对应一个jiiffies值(这个基准时间换算成jiffies值的方法是:用这个时间减去1970-01-01  00:0 ...

  10. linux系统中 库分为静态库和,Linux系统静态库与共享库

    8种机械键盘轴体对比 本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选? This article mainly introduces the statics library and share ...

最新文章

  1. 获取SpringBean对象工具类
  2. 关于虚拟机vmware共享虚拟网卡上网
  3. 下拉推广系统立择火星推荐_下拉词优化不仅仅优化百度,其实还可以优化抖音、京东和阿里巴巴...
  4. MyBatis 缓存详解-cache 缓存
  5. 去杠杆高歌猛进,借呗会倒闭吗?
  6. 软件测试之单元测试之Junit测试使用前准备
  7. JQuery元素操小结
  8. “中国开发者大调查”问卷收集即将结束,快来看这次中奖“末班车”你赶上了吗?
  9. 树和二叉树定义、基本术语和性质
  10. 【火灾检测】基于matlab GUI火灾检测【含Matlab源码 249期】
  11. 手机微信html整人代码大全,让微信卡死的代码是什么 微信整人代码汇总
  12. 卸载搜狗拼音输入法linux,Ubuntu下使用搜狗拼音输入法
  13. javaweb框架和其他知识点总结
  14. 微博、QQ、微信第三方登录 Java 实现实录
  15. android联想搜索不到wifi,联想笔记本搜不到无线网解决办法
  16. rootfs bootfs bootloader
  17. JavaScript中栈内存与堆内存分别是什么?
  18. bootstrap, boosting, bagging
  19. 如何将视频的语音变成文字播放出来?
  20. 运算符的优先级(从高到低)

热门文章

  1. php 按指定长度分割字符串,php实现将字符串按照指定距离进行分割的方法
  2. 一种基于深度神经网络的临床记录ICD自动编码方法
  3. 用计算机画函数图象的软件,自动画出函数图象的软件 真像函数图像绘制器
  4. java画函数图像_怎么用java绘制函数图像
  5. sigmoid和tanh激活函数与其导数的绘图详解
  6. vscode 历史版本1.68.1
  7. 移远 BC95 海思 NBIOT 物联网模块 规格 手册 说明
  8. Quartz.Net定时任务时间表达式设置
  9. Power BI中使用的M语言
  10. REST服务中的异常处理