Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I fix Warning: C4129 'e': unrecognized character escape sequence

Tags:

c

When I write some code with ANSI escape sequence like.... \e[4m ~ \e[0m, I got the error that

C4129 'e': unrecognized character escape sequence

and the program show me that escape sequence did not set and just indicates \e[4Hello\e[0.

How can I fix it?

like image 895
dkdkdk123 Avatar asked Sep 20 '25 00:09

dkdkdk123


1 Answers

The \e is supposed to insert an ESC character (ASCII code 27), but it doesn't exist in standard C, only in some nonstandard extensions.

You can use \33 instead1. (33 is the octal representation of decimal 27.)


1: This will work fine (and is the shortest way) for regular ANSI escape sequences since the following character will always be [. But in case you ever need to use the ESC character in other circumstances, please note that you'll need \033 in case it is followed by a digit between 0 and 7, because otherwise that next digit would errornously be considered part of the octal number. As dxiv mentioned in the comments, it may be the case with some VT100 escape sequences.

like image 137
CherryDT Avatar answered Sep 22 '25 20:09

CherryDT