Skip to content

Instantly share code, notes, and snippets.

@LittleKey
Created November 9, 2018 17:42
Show Gist options
  • Save LittleKey/b321a6b4602e54b0086e2fb8a7ba6f7a to your computer and use it in GitHub Desktop.
Save LittleKey/b321a6b4602e54b0086e2fb8a7ba6f7a to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <signal.h>
#define UNUSED(x) (void)(x)
static volatile int KeepRunning = 1;
void InterceptionSignalHandler(int dummy) {
UNUSED(dummy);
if (KeepRunning) {
KeepRunning = !KeepRunning;
}
}
int main(int argc, char* argv[]) {
char* outChar;
if (argc > 1) {
for (int i = 1; i < argc; ++i) {
if (i == 1) {
outChar = (char*) malloc(strlen(argv[i]));
strcpy(outChar, argv[i]);
continue;
}
char* newChar = (char*) malloc(strlen(outChar) + 1 + strlen(argv[i]));
strcpy(newChar, outChar);
strcat(newChar, " ");
strcat(newChar, argv[i]);
free(outChar);
outChar = newChar;
}
} else {
outChar = (char*) malloc(1);
strcpy(outChar, "y");
}
signal(SIGINT, InterceptionSignalHandler);
while (KeepRunning) {
printf("%s\n", outChar);
}
free(outChar);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment