In previos post I've described how to embed data into object.
The other opprotunity is to store data in the c/c++ array.
Again, I'll use data.txt:
$cat data.txt data fileTo create a source file with this data I'll use xxd utility:
xxd -i data.txt data.c
$cat data.c
unsigned char data_txt[] = {
0x64, 0x61, 0x74, 0x61, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x0a
};
unsigned int data_txt_len = 10;Simple c source file to use this array will look like:
#include <stdio.h>
extern unsigned char data_txt[];
extern unsigned int data_txt_len;
int
main(int argc, char **argv)
{
printf("%d", data_txt_len);
printf("%s", data_txt);
return 0;
}
To compilegcc test.c data.c


No comments:
Post a Comment