j4nw
j4nw

Reputation: 2405

How can I hardcode a file as a byte array?

I have to create some functionality that performs operations on byte arrays, that will be provided by other parts of the program. For testing and development, I've been provided the arrays as files, and simply use them as such:

unsigned char frame_bytes[FRAME_SIZE];
FILE *fp;
fp = fopen("file.xyz", "rb");
fread(frame_bytes, sizeof(unsigned char), FRAME_SIZE, fp);
// test the functionality that operates on frame_bytes

Now I have to test the code on an embedded environment without a file system. Is there any straightforward way to hardcode this file as a byte array?

Upvotes: 1

Views: 984

Answers (1)

Colin
Colin

Reputation: 3524

HxD (which is very useful in itself) from https://mh-nexus.de/en/hxd/ has the option to export as a C array which you would then be able to compile into your application.

I have no affiliation with HxD other than being a happy user.

Upvotes: 5

Related Questions