snprintf problem for byte type variable

I'm programming Nodemcu-32s , with arduiono IDE 1.8.13. I've facing problem formatting byte varibale in snprintf function using the follwoing code:

snprintf (daata, 100,"// %s %c %c %c %c %c %c %c //", id,os,ts, ths, fos, ps, m_s, dc);

Except variable "id", all other variables are byte type.

When the code is run, it shows nothing. just the following: "// D3165464 "

We can’t see your code.

Please show us the declaration of 'daata', at least...

Maybe your bytes are not printable characters? Try "%hhu"

http://www.snippets-r-us.com

Sorry, I didn't write the code.

Here is the code that is been being tested :

char daata [100];

char id[]="1234";

byte os=0, ts=0, ths=0, fos=0, ps=0, m_s=0, dc=0;

void setup ()
{

Serial.begin(115200)
Serial.println("Starting");
delay(100);

} 

void loop ()
{
    snprintf (daata, 100,"// %s %c %c %c %c %c %c %c //", id,os,ts, ths, fos, ps, m_s, dc);
    Serial.println(daata);
    delay(1000);
  
}

What did you expect?

What ASCII character is represented by 0x00?

My code is:

char daata [100];

char id[]="1234";

byte os=0, ts=0, ths=0, fos=0, ps=0, m_s=0, dc=0;

void setup ()
{

Serial.begin(115200)
Serial.println("Starting");
delay(100);

}

void loop ()
{
    snprintf (daata, 100,"// %s %c %c %c %c %c %c %c //", id,os,ts, ths, fos, ps, m_s, dc);
    Serial.println(daata);
    delay(1000);
  
}

I wanted reading a pin value using digitalRead and store it to a byte variable , hence the byte variables will contain either 1 or 0, I expect this output:

// 1234 0 0 0 0 0 0 0 //

but I got this:

// 1234 

how can I put" byte a= 0 or 1" directly to snprintf function ?

%c is for a single ASCII character, try using %d or %i to print a number as ASCII.

%c is the placeholder for a character with the ASCII code of the variable that it is holding the place for. Those variables have the value of (byte) 0x00. The character that is represented by the code 0x00 is the NULL character which is not printable (0x01 is also not printable). You can solve this by inserting the number, using %d, instead of the character (%c). The (byte) number 0 is printable. The result is still a string.

snprintf (daata, 100, "// %s %d %d %d %d %d %d %d //", id, os, ts, ths, fos, ps, m_s, dc);

Result:

// 1234 0 0 0 0 0 0 0 //
// 1234 0 0 0 0 0 0 0 //
// 1234 0 0 0 0 0 0 0 //

how can I put" byte a= 0 or 1" directly to snprintf function ?

You could add ‘0’ to it (%c), or you could cast it to “int” (%d)