Re: want a "here doc" equivalent in "c"

  • Follow


char *text[] = {
/*X*/
	"line 1\n",
	"line 2\n",
	...,
	"line n\n",
/*Y*/
	0
};
char **t;
FILE *script = fopen("scriptpath","w");
int rc;

for (t=text; *t; t++) fputs(*t,script);
fclose(script);
rc = system("sh -c '. script' or whatever magic needed to execute the file");

The lines between X and Y have to have quotes and backslashes backslashed escaped,
besides the initial '"' and trailing 'n",' for each line. It's a pain to do this
by hand. It's easy to write a simple filter for this and then do something like
	herefilter <textfile >textfile.here
and replace the /*X*/.../*Y*/ with
	#include "textfile.here"

I do something similar quite often to insert Tcl scripts into C programs
with the makefile calling the filter and compiling the file.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
Title does not dictate behaviour.
0
Reply derkgwen (343) 9/4/2003 6:46:40 AM


0 Replies
31 Views

(page loaded in 0.017 seconds)


Reply: