feat(C/Sully): adding the Sully program
This commit is contained in:
parent
cb93494c08
commit
7c9ab02454
1 changed files with 30 additions and 0 deletions
30
C/Sully/Sully.c
Normal file
30
C/Sully/Sully.c
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define FORMAT "#include <stdio.h>%1$c#include <stdlib.h>%1$c%1$c#define FORMAT %3$c%4$s%3$c%1$c%1$cint main(void)%1$c{%1$c%2$cstatic char buffer[42];%1$c%2$cint i = %5$d;%1$c%1$c%2$cif (i <= 0)%1$c%2$c%2$creturn 0;%1$c%1$c%2$csnprintf(buffer, sizeof(buffer), %3$cSully_%%d.c%3$c, i - 1);%1$c%1$c%2$cFILE *f = fopen(buffer, %3$cw%3$c);%1$c%1$c%2$cfprintf(f, FORMAT, 10, 9, 34, FORMAT, i - 1);%1$c%2$cfclose(f);%1$c%1$c%2$csnprintf(buffer, 42, %3$ccc Sully_%%1$d.c -o Sully_%%1$d%3$c, i - 1);%1$c%2$cif (system(buffer) != 0)%1$c%2$c%2$cexit(1);%1$c%1$c%2$cif (i > 0)%1$c%2$c{%1$c%2$c%2$csnprintf(buffer, 42, %3$c./Sully_%%d%3$c, i - 1);%1$c%2$c%2$csystem(buffer) == 0 || (exit(1), 0);%1$c%2$c}%1$c}%1$c"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
static char buffer[42];
|
||||||
|
int i = 5;
|
||||||
|
|
||||||
|
if (i <= 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
snprintf(buffer, sizeof(buffer), "Sully_%d.c", i - 1);
|
||||||
|
|
||||||
|
FILE *f = fopen(buffer, "w");
|
||||||
|
|
||||||
|
fprintf(f, FORMAT, 10, 9, 34, FORMAT, i - 1);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
snprintf(buffer, 42, "cc Sully_%1$d.c -o Sully_%1$d", i - 1);
|
||||||
|
if (system(buffer) != 0)
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
if (i > 0)
|
||||||
|
{
|
||||||
|
snprintf(buffer, 42, "./Sully_%d", i - 1);
|
||||||
|
system(buffer) == 0 || (exit(1), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue