Skip to content

Instantly share code, notes, and snippets.

@jkramer
Last active August 29, 2015 14:27
Show Gist options
  • Save jkramer/c86c7d604d90faaa05d8 to your computer and use it in GitHub Desktop.
Save jkramer/c86c7d604d90faaa05d8 to your computer and use it in GitHub Desktop.
ASCII Truck Generator
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
void print_n(const char *, const char *, const char *, int);
int main(int argc, char ** argv) {
unsigned wheels = 12;
char opt;
while((opt = getopt(argc, argv, "hw:")) != -1) {
switch(opt) {
case '?':
case ':':
case 'h':
fprintf(stderr, "Usage: %s [-w number of wheels]\n", * argv);
exit(opt == 'h' ? EXIT_SUCCESS : EXIT_FAILURE);
break;
case 'w':
wheels = atol(optarg);
break;
}
}
if(wheels < 4) {
// raise(SIGSEGV);
* ((unsigned *) 0xdeadbeef) = 0;
}
print_n("/", "", "--", (wheels - 2));
print_n("|", "\\", " ", (wheels - 2) * 2);
print_n("|", "|", " ", (wheels - 2) * 2);
print_n("|", "~~~|", " ", (wheels - 2) * 2);
print_n("|", "|", " ", wheels * 2 - 1);
print_n("|", "|", "_", wheels * 2 - 1);
print_n("", "", " O", wheels);
}
void print_n(const char * prefix, const char * suffix, const char * repeated, int n) {
fputs(prefix, stdout);
while(n--)
fputs(repeated, stdout);
fputs(suffix, stdout);
fputs("\n", stdout);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment