As I am new to embedded programming I am not able to understand what is "%s\xC2\xB0" ? I know %s is for string

StackOverflow https://stackoverflow.com/questions/15380738

  •  23-03-2022
  •  | 
  •  

Question

(void)sprintf(Thermo_Buff,"%s\xC2\xB0""",a); //to add to buffer
Was it helpful?

Solution

In string literals, a backslash \ is used as a prefix for special characters. I'm sure you know about newline ("\n") for example.

If the special character after the backslash is an x then it means that the next two characters are hexadecimal digits, and those two digits are the translated by the compiler into a character.

In your example the sprintf call adds a string, and then two separate characters based on the hexadecimal numbers 0xc2 and 0xb0, which is UTF-8 for a degree character (see e.g. this reference).

OTHER TIPS

That's a degree sign, encoded as UTF-8 unicode.

You can have a look at a more complete list of characters and what they look like in UTF-8 here.

In C, something in the format \x??? in a string literal, where ??? are numbers, is a Unicode escape. It is a way of entering Unicode characters which cannot be entered with a keyboard. In this case, if you look at this table, you will see that the escape sequence c2 b0 (written \xC2\xB0 in your code encodes a degree sign - so that is what this means.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top