A text file to C string converter

By Malcolm McLean Homepage

texttostring is a simple utility that converts a plain text file to a string suitable for inclusion in C programs.

Simply evoke it on the command line
texttostring < infile.txt > [id]

Usually you will want to redirect the output to a file.

If you do not specify an identifier, the filename will be used as the name of the string, with non-legal C characters converted to underscores. If the filname doen to begin with a alphabetical character, the letter 'a' will be prepended to make a legal C identifer. Underscores cannot be used because the double underscore sequence is reserved for the implementation.

Line length is kept to about 100 characters, by splitting the string over several lines. To aid readability, the program tries to split on newlines.

Escape characters are of course replaced by their C sequence equivalents.

The utility is provided as C source. It should compile and run on any ANSI C system.

It is completely free, but I do ask that you email me if you fix any bugs or amke any enhancements.

The source code is here