Write a C program that plays a game of Mad Libs with the user. Specifically, the program should do the following:
a. Declare five character arrays of size 20.
b. Prompt the user, five times, to enter a word of some type. Each
word is stored in a different character array. The word types could
be vague, such as "noun," "adjective," or "adverb," or they could
be specific, such as "color," "animal," or "name."
c. Using printf()'s %s format specifier, output a short story that
includes each of these five words.
The story told by the program can be anything you want. Below is a
sample story that you're welcome to use. The words that will be
replaced with inputs are shown in italics.
"Every morning, name gets out of bed and ready for class. Name
eats food for breakfast, then pets their animal and verb
s their teeth. After name puts on noun , name is ready
to go."
A sample run of the program with "Munster," "tuna," "human,"
"sharpen," and "attitude" as user inputs might look like the
following:
Welcome to Mad Libs!
Enter a name: Munster
Enter a food: tuna
Enter an animal: human
Enter a verb: sharpen
Enter a noun: attitude
Every morning, Munster gets out of bed and ready for class. Munster
eats tuna for breakfast, then pets their human and sharpens
their teeth. After Munster puts on attitude, Munster is ready to
go.
#include <stdio.h>
int main(void) {
char name[20], food[20], animal[20], verb[20], noun[20];
printf("Welcome to Mad Libs!\nEnter a name: ");
scanf("%s", name);
printf("Enter a food: ");
scanf("%s", food);
printf("Enter a animal: ");
scanf("%s", animal);
printf("Enter a verb: ");
scanf("%s", verb);
printf("Enter a noub: ");
scanf("%s", noun);
printf("Every morning, %s gets out of bed and ready for class.
Munster eats %s for breakfast, then pets their %s and %ss their
teeth. After Munster puts on %s, %s is ready to go.", name, food,
animal, verb, noun, name);
return 0;
}
// Hit the thumbs up if you are fine with the answer.
Happy Learning!
Get Answers For Free
Most questions answered within 1 hours.