![]() |
Inserting text blob into a C program
I'm writing a C program, and using Autotools. I have a large text file that I need to include verbatim, as data for my program.
I used to have a hacked-together Perl script that would take a file like this: Code:
A Rabbi, a Priest, and a Minister walked into a bar.Code:
#define TXT_DATA \I found this site that contains instructions for doing exactly what I want, but that technique requires GNU's ld, and the whole point of using Autotools in the first place is to make my project platform- and compiler-independent. Anybody got any ideas? Edit: I should point out that, according to the Autotools help, I can do this with a script called either "txtc.sh" or "txtc.sh.in". Unfortunately, Google can't find such a script, and it's not in any package that I can find. |
not sure why a normal file pointer declaration wouldnt work:
Code:
FILE * fstream; char temp[100];edit: else you would need to emulate that in a script by cat-ing (echo \#define, your joke, then the rest of your c-file) for each file you are editing. |
AFAIK he wants the text embedded into the executable.
|
Yes, the text has to be embedded in the executable. Also, cat wouldn't work, since it would also need to escape quotes, add quotes to every line, add a backslash to the end of every line, etc., etc., etc.
For the moment (so the project can go ahead), I'm going to recreate my Perl script. However, I would really like to know if there's any way to do this. Thanks! Edit: Something like a Windows resource, for those of you familiar with Windows programming. |
|
It's a command-line application (so far).
|
I wasn't saying you should use Qt (even though Qt is perfectly suited for non-GUI apps), I just made a suggestion.
|
In my opinion, your Perl script that translates the plain text into a format suitable for inclusion as a literal string is the right way. The script shouldn't be very hard to reproduce.
--- rod. |
I also see nothing wrong with your Perl script solution.
|
Code:
#include <iostream> |
What's the point of that, and can't you see the OP isn't using C++?
|
Quote:
I've recreated my Perl script, so unless anyone has a better idea, that's what I'll use. Thanks for your help, everyone. |
I think you should just go with your Perl script.
And mark the thread as solved (in Thread Tools). |
| All times are GMT -5. The time now is 07:20 AM. |