FileToStringLiteral is a very simple program that converts a file into a literal string for the C language. This allows you to embed files into source code.
If converting PNG images, consider optimizing them first.
The string will be split on regular intervals to make it less hard on your text editor, so the string only works with languages/compilers that automatically concatenate strings when written like this:
"first". You can remove the split yourself or add a concatenation operator in-between if you want to or whatever.
How it works
Each byte of the file is read, and then written into the string as whatever code/character corresponds to the same byte value. You can then read the string as binary data from your code.
- Bytes that represent alphabetical and numerical (and some others like
$) ASCII characters can be inserted just by adding that character into the string.
- A few more ASCII values can be inserted with escape codes, for example
\rinserts a "carriage return".
- A few ASCII characters have to be escaped, for example
"ends the string, so it has to be written as
\escapes the next character(s) so it has to be written as
- Any remaining byte values are inserted with a 3-digit octal code, for example
There's some options that could be added, for example the ability to configure the string to be compatible with different programming languages, or buttons for opening a file picker or exporting a file. I only use C and need this tool very rarely, so I don't have personal motivation to add more features to it. I may add them some day though.
Send me a message if you want this to work for another programming language, also give me an example of how the string needs to be changed because I probably won't bother researching that myself.
Linux version is planned, I will make it sometime in the future when I get more familiar with Linux development.
Mac version not planned.
Download FileToStringLiteral_1-0-1.zip - 146 KB
Report bugs/problems or request features: find my contact here.