I’d suggest using (unix util)xxd for this.
you can use it like so
$ echo hello world > a
$ xxd -i a
outputs:
unsigned char a[] = {
0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x0a
};
unsigned int a_len = 12;
More Related Contents:
- Including one C source file in another?
- C circular dependency
- What is a good reference documenting patterns of use of X-Macros in C (or possibly C++)?
- What are the applications of the ## preprocessor operator and gotchas to consider?
- Macro definition to determine big endian or little endian machine?
- What is the meaning of lines starting with a hash sign and number like ‘# 1 “a.c”‘ in the gcc preprocessor output?
- Are typedef and #define the same in c?
- What are the benefits of a relative path such as “../include/header.h” for a header?
- Standard alternative to GCC’s ##__VA_ARGS__ trick?
- What are the valid characters for macro names?
- Where is PATH_MAX defined in Linux?
- Creating your own header file in C
- Does the C preprocessor strip comments or expand macros first? [duplicate]
- Are empty macro definitions allowed in C? How do they behave?
- Variadic macro trick
- How to use #if inside #define in the C preprocessor?
- #ifdef inside #define
- Spaces inserted by the C preprocessor
- Is there a good reason for always enclosing a define in parentheses in C?
- Detecting Endianness
- When can you omit the file extension in an #include directive?
- C Macros to create strings
- Macro and function with same name
- Include all files in a directory?
- Is the sizeof(enum) == sizeof(int), always?
- Should variable definition be in header files?
- How can I implement a dynamic dispatch table in C
- Why can’t I use sizeof in a preprocessor condition?
- How can I make a char string from a C macro’s value?
- Macros to create strings in C