用C回车? [英] Carriage return in C?

查看:199
本文介绍了用C回车?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的程序的输出是:

我没有得到 \\ r 回车如何在这个程序,在实际任何一个可以帮助我呢?

 的#include<&stdio.h中GT;
#包括LT&;&CONIO.H GT;无效的主要()
{
    的printf(\\捉住);
    的printf(\\ BSI);
    的printf(\\ RHA);
    _getch();
}


解决方案

从5.2.2 / 2(字符显示语义):


  

\\ b 退格键的)将活动
  位置在previous位置
  当前行。如果活性
  位置是在初始位置
  一条线,在显示器的行为
  设备是不确定的。


  
  

\\ n 新行的)将活动
  位置的初始位置
  下一行


  
  

\\ r 回车的)将活动
  位置的初始位置
  当前行。


在这里,你的code生产:


  • <&NEW_LINE GT; AB

  • \\ b :回到一个字符

  • SI :覆盖 B 取值 (产生 ASI 第二行)

  • \\ r :在当前行的开头后面

  • :覆盖前两个字符(生产第二行)

在结束时,输出是:

  \\ NHAI

Output of Following program is : hai

I didn't get how the \r carriage return works in this program and in real can any one help me out ?

#include <stdio.h>
#include<conio.h>

void main()
{
    printf("\nab");
    printf("\bsi");
    printf("\rha");
    _getch();
}

解决方案

From 5.2.2/2 (character display semantics) :

\b (backspace) Moves the active position to the previous position on the current line. If the active position is at the initial position of a line, the behavior of the display device is unspecified.

\n (new line) Moves the active position to the initial position of the next line.

\r (carriage return) Moves the active position to the initial position of the current line.

Here, your code produces :

  • <new_line>ab
  • \b : back one character
  • write si : overrides the b with s (producing asi on the second line)
  • \r : back at the beginning of the current line
  • write ha : overrides the first two characters (producing hai on the second line)

In the end, the output is :

\nhai

这篇关于用C回车?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆