如何去上一行的C代码 [英] How to go to the previous line in a C code

查看:109
本文介绍了如何去上一行的C代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果为以下代码:

printf("HEllo\n");    // do not change this line.
printf("\b\bworld");

我需要一个输出:Helloworld(单行)。但这不行。有人可以解释原因吗?和其他转义序列如果有的话。

I need an output: Helloworld (In a single line). But this does not work fine. Could anyone please explain the reason? And other escape sequence if any.

推荐答案

从第一个printf中删除\\\
。它将光标移动到新行。

Remove "\n" from your first printf. It moves the cursor to a new line.

这里是转义序列的列表。

Here is the list of escape sequences.

如果你不能删除\\\
,那么你可以做一个没有这些字符串的子串的副本。请参见以下示例:

If you can't remove "\n", then you can do make a copy of a substring without these charaters. See the following example:

  const char* from = "12345678";
  char *to = (char*) malloc(6);
  strncpy(to, from+2, 5);

您需要的是确定\字符的索引。

All you need is to determine the index of "\n" characters.

这篇关于如何去上一行的C代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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