Skip to content

Instantly share code, notes, and snippets.

@taeber
Created November 13, 2019 23:13
Show Gist options
  • Save taeber/97985286a1739f56bedbd977ca8e5566 to your computer and use it in GitHub Desktop.
Save taeber/97985286a1739f56bedbd977ca8e5566 to your computer and use it in GitHub Desktop.
Fake say program
// Fake say program
//
// Author:
// Taeber Rapczak <[email protected]>
//
// Compile:
// $ cc -o say fakesay.c
// Example:
// $ ./say hi
// $ ./say alexa unlock front door
// Alert! Front door unlocked.
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[]) {
const char *expected[] = {"", "alexa", "unlock", "front", "door"};
const char *together = "alexa unlock front door";
if (argc == 2 && strcmp(together, argv[1]) == 0)
goto SUCCESS;
if (argc != sizeof(expected)/sizeof(expected[0]))
return 1;
for (int i = 1; i < sizeof(expected)/sizeof(expected[0]); i++) {
if (strcmp(argv[i], expected[i]) != 0)
return 1;
}
SUCCESS:
puts("Alert! Front door unlocked.");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment