/* acro.c */ /* QUICK INSTALL JUST TO TRY IT OUT Compile: gcc acro.c -o acro Then, try: ./acro DVD DVI CD and you get CD Compact Disc DVI ? DVD Digital Versatile Disc Note: This solution uses recursion which is not common in C. Also, a professional solution would use SQL (or at least XML). (Data should not be hard coded but put in a separate file.) News: There is in fact an XML, and a web/MySQL, version of this application on my home page: http://user.it.uu.se/~embe8573 COMPLETE INSTALL IF YOU REALLY LIKE IT 1. Compile as above to get the binary executable 2. Put that file in a folder listed when you type `echo $PATH` 3. In the same folder as this (acro.c) file, find acro.1.gz 4. Move that file to /usr/share/man/man1/ (Note: Although an archive, view the groff code in Emacs like any other file.) */ #include #include #include const int EXIT_FAIL = 1; const int EXIT_OK = 0; const int EQ_STR = 0; int main(int argc, char** argv) { if (argc == 1) { fprintf(stderr, "Usage: acro needs at least one argument.\n"); return EXIT_FAIL; } else { int argument_index = argc - 1; char *str_acro = malloc(strlen(argv[argument_index])); strcpy(str_acro, argv[argument_index]); printf("%s\t", str_acro); if (strcmp(str_acro, "CD") == EQ_STR) { printf("Compact Disc"); } else if (strcmp(str_acro, "DVD") == EQ_STR) { printf("Digital Versatile Disc"); } else { printf("?", str_acro); } putchar('\n'); free(str_acro); if (argc != 2) { main(--argc, argv); } } return EXIT_OK; }