话不多说先放程序
#include <stdio.h>
#include <stdlib.h>
char bufp[10000];
char bufq[10000];
char bufb[10000];
char bufa[10000];
char* escape(char *buf) {
char* nb = (char*)malloc(10000);
char *base = nb;
while (*buf) {
if (*buf == '\n') {
*nb = '\\'; ++nb;
*nb = 'n'; ++nb;
} else if (*buf == '\"') {
*nb = '\\'; ++nb;
*nb = '\"'; ++nb;
} else if (*buf == '\\') {
*nb = '\\'; ++nb;
*nb = '\\'; ++nb;
} else if (*buf == '\'') {
*nb = '\\'; ++nb;
*nb = '\''; ++nb;
} else {
*nb = *buf; ++nb;
}
++buf;
}
*nb = '\0';
return base;
}
void a() {
sprintf(bufp, "%s", "#include <stdio.h>\n#include <stdlib.h>\n\nchar bufp[10000];\nchar bufq[10000];\nchar bufb[10000];\nchar bufa[10000];\n\nchar* escape(char *buf) {\n char* nb = (char*)malloc(10000);\n char *base = nb;\n while (*buf) {\n if (*buf == \'\\n\') {\n *nb = \'\\\\\'; ++nb;\n *nb = \'n\'; ++nb;\n } else if (*buf == \'\\\"\') {\n *nb = \'\\\\\'; ++nb;\n *nb = \'\\\"\'; ++nb;\n } else if (*buf == \'\\\\\') {\n *nb = \'\\\\\'; ++nb;\n *nb = \'\\\\\'; ++nb;\n } else if (*buf == \'\\\'\') {\n *nb = \'\\\\\'; ++nb;\n *nb = \'\\\'\'; ++nb;\n } else {\n *nb = *buf; ++nb;\n }\n ++buf;\n }\n *nb = \'\\0\';\n return base;\n}\n\n");
sprintf(bufb, "%s", "void b() {\n char *p = escape(bufp), *b = escape(bufb), *q = escape(bufq);\n sprintf(bufa, \"void a() {\\n sprintf(bufp, \\\"%%s\\\", \\\"%s\\\");\\n sprintf(bufb, \\\"%%s\\\", \\\"%s\\\");\\n sprintf(bufq, \\\"%%s\\\", \\\"%s\\\");\\n}\\n\\n\", p, b, q);\n free(p); free(b); free(q);\n}\n\n");
sprintf(bufq, "%s", "int main() {\n a();\n b();\n printf(\"%s%s%s%s\", bufp, bufa, bufb, bufq);\n}\n");
}
void b() {
char *p = escape(bufp), *b = escape(bufb), *q = escape(bufq);
sprintf(bufa, "void a() {\n sprintf(bufp, \"%%s\", \"%s\");\n sprintf(bufb, \"%%s\", \"%s\");\n sprintf(bufq, \"%%s\", \"%s\");\n}\n\n", p, b, q);
free(p); free(b); free(q);
}
int main() {
a();
b();
printf("%s%s%s%s", bufp, bufa, bufb, bufq);
}