Search code examples
carraysprintfuint8t

How to print uint8_t bytes array?


I have the following code:

uint16_t BufferSize = BUFFER_SIZE;
uint8_t Buffer[BUFFER_SIZE];

Buffer size is 64 bytes and is filled as:

Buffer[0] = 'P';
Buffer[1] = 'I';
Buffer[2] = 'N';
Buffer[3] = 'G';
Buffer[4] = 0;
Buffer[5] = 1;
Buffer[6] = 2;
Buffer[7] = 3;
Buffer[8] = 4;
.
.
.
Buffer[63] = 59;

I am trying to print the content of the Buffer using:

for( i = 0; i < BufferSize; i++ )
{

    PRINTF(Buffer[i]);

}

Also tried:

for( i = 0; i < BufferSize; i++ )
{
    PRINTF((const char*) Buffer[i]);
}

But it is not working.


Solution

  • You should refer to the syntax of printf. C treats small and capital letters differently so you should write something like this:

    printf("%c", Buffer[i])