fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main(int argc, char **argv) {
  4. if (strcmp(*argv, "stop")) {
  5. char *in = malloc(99); // assume it worked
  6. fgets(in, 99, stdin); // assume it worked
  7. *(in+strcspn(in, "\n")) = 0; // remove trailing ENTER
  8. main(argc + 1, &in); // memory leak
  9. } else {
  10. printf("Stopped after %d entries.\n", argc - 1);
  11. }
  12. }
  13.  
Success #stdin #stdout 0s 9424KB
stdin
foo
bar
baz
quux
stop
more
stdout
Stopped after 5 entries.