c#无效的转义序列_错误:C中无效的转义序列 常见的C程序错误

c#无效的转义序列

Sometimes, while writing Escape Sequences in C program, we mistakenly typed an invalid escape sequence, which does not give any error but does not give the expected result.

有时,在用C程序编写Escape序列时,我们错误地键入了一个无效的 Escape 序列 ,它不会产生任何错误,但不能给出预期的结果。

For example, if we want to print a "new line" between two words in a text and mistakenly typed \m instead of \n.

例如,如果我们要在文本中的两个单词之间打印“换行” ,并错误地键入\ m而不是\ n 。

Consider the program:

考虑该程序:

#include <stdio.h>

int main(void) {
	
	printf("Hello world\mHow are you?");
	
	return 0;
}

Output

输出量

    Hello worldmHow are you?

We wanted to print "Hello world" and "How are you?" in separate lines but there is an invalid escape sequence \m. Thus, the result is "Hello worldmHow are you?".

我们想打印“ Hello world”“你好吗?” 在单独的行中,但是存在无效的转义序列\ m 。 因此,结果是“ Hello worldm,你好吗?”

如何修复“ C中无效的转义序列”错误 (How to fix "Invalid escape sequence in C" error)

To fix this and such errors, you should know about all escape sequences and use them properly.

要解决此错误和此类错误,您应该了解所有转义序列并正确使用它们。

Read: Escape sequences in C

阅读: C语言中的转义序列

Correct code

正确的代码

#include <stdio.h>

int main(void) {
	
	printf("Hello world\nHow are you?");
	
	return 0;
}

Output

输出量

    Hello world
    How are you?

翻译自: https://www.includehelp.com/c-programs/invalid-escape-sequence-in-c.aspx

c#无效的转义序列

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值