frischky
frischky

Reputation: 63

Convert char array to string (including non printable characters) in C?

Say I have the following:

static const unsigned char key[] = {
    0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
    0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff
};

How do I convert this into a string (including unprintable characters) in C?

I have searched Google and SO... but only manage to find how to convert if the characters are human-ASCII 0-9 A-Z.

Upvotes: 1

Views: 708

Answers (1)

Paul
Paul

Reputation: 141839

A C string is just a char array that is null-terminated, so all you need to do is copy the array to a new array that has a size one larger, and set the last element in that array to 0.

Upvotes: 5

Related Questions