This is supposed to be a silly "Mad Lib" game. I just copied the example from my course's book and made my changes. The example executes just fine, so what am I missing? Is there any way I can make this code better and more efficient?
// This program plays a word game similar
// to Mad Libs.
#include "DarkGDK.h"
#include <string.h>
// Function prototypes
void getInput(char[], char[], char[], char[], char[], char[], char[]);
void displayStory(char[], char[], char[], char[], char[], char[], char[]);
//********************************************************
// DarkGDK function *
//********************************************************
void DarkGDK()
{
// Constants for array sizes
const int WORD_SIZE = 30;
// Arrays for the user's input
char color[WORD_SIZE];
char food[WORD_SIZE];
char creamOrCrunch[WORD_SIZE];
char number[WORD_SIZE];
char utensil[WORD_SIZE];
char verb[WORD_SIZE];
char noun[WORD_SIZE];
// Get the user's words.
getInput(color, food, creamOrCrunch, number, utensil, verb, noun);
// Display the story.
displayStory(color, food, creamOrCrunch, number, utensil, verb, noun);
// Wait for the user to press a key.
dbPrint("Press any key to exit.");
dbWaitKey();
}
//********************************************************
// The getInput function accepts arrays for each of the *
// words that the user must provide. It gets input for *
// those words and stores that input in the arrays. *
//********************************************************
void getInput(char color[], char food[], char creamOrCrunch[], char number[], char utensil[], char verb[], char noun[])
{
// Get a color.
dbPrint("Enter a color:");
strcpy( color, dbInput() );
// Get the name of a food.
dbPrint("Enter a food:");
strcpy( food, dbInput() );
// Ask the user; Creamy or Crunchy?.
dbPrint("Creamy or Crunchy?:");
strcpy( creamOrCrunch, dbInput() );
// Get a number.
dbPrint("Enter a number:");
strcpy( number, dbInput() );
// Get the name of a kitchen utensil.
dbPrint("Enter the name of a kitchen utensil:");
strcpy( utensil, dbInput() );
// Get a verb.
dbPrint("Enter a verb:");
strcpy( verb, dbInput() );
// Get a noun.
dbPrint("Enter a noun:");
strcpy( noun, dbInput() );
}
//********************************************************
// The displayStory function accepts arrays containing *
// the user's words. It displays the story with these *
// words filled into the blanks. *
//********************************************************
void displayStory(char color[], char food[], char creamOrCrunch[], char number[], char utensil[], char verb[], char noun[])
{
// Constants for array sizes
const int LINE_SIZE = 80;
// Arrays for the lines of output
char line1[LINE_SIZE];
char line2[LINE_SIZE];
char line3[LINE_SIZE];
char line4[LINE_SIZE];
char line5[LINE_SIZE];
char line6[LINE_SIZE];
char line7[LINE_SIZE];
// Build line 1.
strcpy( line1, "1. Select the type of bread you want to use. Many prefer the taste of ");
strcat( line1, color );
strcat( line1, " while others prefer wheat bread because it is healthy.");
// Build line 2.
strcpy( line2, "2. Choose the flavor of Jam/Jelly. I personally prefer");
strcat( line2, food );
strcat( line2, " jam, but you can use whatever you want. ");
// Build line 3.
strcpy( line3, "3. Grab your ");
strcat( line3, creamOrCrunch );
strcat( line3, " peanut butter jar.");
// Build line 4.
strcpy( line4, "4. Take out ");
strcat( line4, number );
strcat( line4, " slices of bread.");
// Build line 5.
strcpy( line5, "5. Use a ");
strcat( line5, utensil );
strcat( line5, " to spread the jam.");
// Build line 6.
strcpy( line6, "6. Now ");
strcat( line6, verb );
strcat( line6, " the peanut butter onto the bread.");
// Build line 7.
strcpy( line7, "7. Put them together, and you have a PB&J");
strcat( line7, noun );
strcat( line7, ".");
// Display the story.
dbPrint();
dbPrint("How to make a PB & J:");
dbPrint("-------------------");
dbPrint(line1);
dbPrint(line2);
dbPrint(line3);
dbPrint(line4);
dbPrint(line5);
dbPrint(line6);
dbPrint(line7);
dbPrint();
}