home *** CD-ROM | disk | FTP | other *** search
- // Acronymity
- // © 2000 by Karl Kornel (kornel.1@osu.edu)
- // Made during MacHack 2000
- // Changes & Redistribution allowed is credit given
-
- /* Our headers */
- #include <iostream.h> // Basic input/output streams
- #include <iomanip.h> // Stream formatting
- #include <stdlib.h> // Standard functions
- #include <fstream.h> // For file stuff
- #include <unistd.h> // For sleep()
- #include <string.h> // For string stuff
-
- /* Our special include */
- #include "settings.h" // Our user-definable settings
-
- /* The prototypes for our support functions */
- bool confirmQuit(const char *acronym);
- bool confirmAdd(const char *acronym);
- void printHelp(void);
- void clearChar(char *,const int);
- void cleanAcronym(char *);
- bool isLetter(const char);
- char makeItLower(const char);
-
- /* The prototypes for our file-interaction functions */
- void openFiles(void);
- int getWord(char *, const char);
- void closeFiles(void);
-
- /* Our functions */
- int main(void) {
- openFiles();
-
- const int finalPhraseLength = (acronymLength * wordLength) - acronymLength; // Obvious
- char acronym[acronymLength + 1]; // The acronym
- char word[wordLength + 1]; // Holders for each word
- char finalPhrase[finalPhraseLength]; // The final phrase
-
- int realAcronymLength = acronymLength; // The length of the actual acronym (minus the \0)
- int realWordLength; // The length of the actual word (minus the \0)
- int realPhraseLength = 0; // The length of the actual phrase (minus the \0)
-
- /* Initialize the strings */
- clearChar(acronym,acronymLength);
- clearChar(word,wordLength);
- clearChar(finalPhrase,finalPhraseLength);
-
- /* Display credits & intro, get acronym */
- cout << "ACROYNMity - By Karl Kornel\n"
- << "Free use for all MacHackers\n"
- << "©2000 Karl Kornel for anyone else\n\n"
- << "Made in the USA for MacHack 2000\n"
- << "Thanks to Mike Ferris for the words.\n"
- << "Thanks to Eric Tolmach for the support\n\n""" << endl;
-
- cout << "Enter an acronym for me to expand. Enter quit to quit.\n"
- << "Enter add for information on adding words.\n"
- << "The acronym can be up to " << acronymLength <<" characters long\n\n"
- << "Acronym...: ";
-
- cin >> acronym;
-
- /* Transfer the call for 'add' or 'quit' */
- if (confirmQuit(acronym))
- exit(0);
- else if (confirmAdd(acronym)) {
- printHelp();
- exit(0);
- }
-
- /* Clean the acronym */
- cout << "Stand by, cleaning up acronym..." << endl;
- cout << " Acronym " << acronym << " has been converted to ";
- cleanAcronym(acronym); // Clean it up
- cout << acronym << '.' << endl;
-
- sleep(3);
-
- /* Get ready to reveal the magic phrase */
- cout << "\n\n\n\n\n" << endl << "Expanding acronym " << acronym << "..." << endl;
-
- cout << "Acronym " << acronym << " expands to the letters/words:\n";
-
- /* Find out how long the phrase is */
- for (int temp = 0;temp <= acronymLength;temp++)
- if (acronym[temp] == '\0') {
- realAcronymLength = temp;
- break;
- }
-
- /* Now, start displaying and constructing the components */
- for (int temp = 1;temp <= realAcronymLength;temp++) {
- /* Output the letter */
- cout << ' ' << acronym[temp - 1] << ": "; // The letter & some space
-
- /* Get the word & find out how long it is */
- realWordLength = getWord(word,acronym[temp - 1]); // Get the word & it's real length
- for (int temp2 = 1;temp2 <= realWordLength;temp2++) // For each character in the word
- cout << word[temp2 - 1]; // Output the character
- cout << endl; // Output a newline
-
- /* Add the word to the phrase */
- strcat(word," "); // Add a space
- strcat(finalPhrase,word);
- }
- cout << "The phrase: " << finalPhrase << endl;
-
- /* Finally, output everything again */
- for (int i=0;i <= 50 - 1;i++)
- cout << '\n';
- cout << endl;
-
- cout << "Before, you had\n\n" << acronym << endl;
-
- cout << "\n\n\nNow, you have\n\n" << finalPhrase;
-
- /* Lastly, close everything down */
- closeFiles();
- }