Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does sprintf not work when \"%s\" is used?

Tags:

c

I'm using sprintf with the IMXRT1021 NXP microcontroller but not getting the required output.

Library: Redlib (nohost-nf)

I have tried both ways but the result is the same.

sprintf(at,"AT=\x22%s\x22,\x22%s\x22\r\n","abcdef","123456");

sprintf(at,"AT=\"%s\",\"%s\"\r\n","abcdef","123456");

Expected output:

AT="abcdef","123456"\r\n

Actual output:

AT=\"abcdef\",\"123456\"\r\n
like image 337
jtro Avatar asked Sep 20 '19 13:09

jtro


1 Answers

It depends on what you are talking about.

If you were to output this into a terminal, the string you would see is the one you expected:

AT="abcdef","123456"   # plus newline etc.

However, the C representation of that string is:

"AT=\"abcdef\",\"123456\"\r\n"
like image 158
Acorn Avatar answered Sep 22 '22 07:09

Acorn