Files
42_EXT_01_dr_quine/C/3_Sully/Sully.c
asus bd9b9c1912 - changed sully to decrement from 5 included to 0
- changed sully makefile to adapt to different starting decrement number
2024-01-28 14:42:44 +01:00

9 lines
929 B
C

#define _GNU_SOURCE /* for asprintf */
#include <stdlib.h> /* for free and system */
#include <stdio.h>
#define xstr(s) #s
#define str(s) xstr(s)
#define FT(s) int main() { char *before = "#define _GNU_SOURCE /* for asprintf */\n#include <stdlib.h> /* for free and system */\n#include <stdio.h>\n#define xstr(s) #s\n#define str(s) xstr(s)\n#define FT(s) "; char *quine = s; char *after = "\nint i = %i;\nFT(str(FT(s)))\n"; if (i >= 0) {char *kid_name; char *kid_name_c; char *decremented_after; char *cmd; asprintf(&kid_name, "Sully_%i", i); asprintf(&kid_name_c, "%s.c", kid_name); FILE *file = fopen(kid_name_c, "w"); asprintf(&decremented_after, after, i - 1); fprintf(file, "%s%s%s", before, quine, decremented_after); fclose(file); asprintf(&cmd, "clang %1$s -o %2$s ; ./%2$s", kid_name_c, kid_name); system(cmd); free(cmd); free(kid_name_c); free(kid_name); free(decremented_after); } return 0; }
int i = 5;
FT(str(FT(s)))