且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将文件转换为 C/C++ 源代码数组的脚本/工具

更新时间:2021-07-30 02:04:21

在 Debian 和其他 Linux 发行版上默认安装(连同 vim)xxd 工具,哪个,给定 -i 选项,可以做你想做的事:

On Debian and other Linux distros is installed by default (along with vim) the xxd tool, which, given the -i option, can do what you want:

matteo@teodeb:~/Desktop$ echo Hello World! > temp
matteo@teodeb:~/Desktop$ xxd -i temp 
unsigned char temp[] = {
  0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21,
  0x0a
};
unsigned int temp_len = 13;