Solution for Exercise 7-11
ex0711
#include <stdio.h>
int main()
{
char prompt[] = "Program to Destroy the World\nPress Enter to explode:";
printf("%s",prompt);
getchar();
return(0);
}
Output
Program to Destroy the World
Press Enter to explode:
Notes
* The newline character, \n, can fit into a string at any spot.
* The reason the prompt string doesn't terminate with a newline is that the output looks better without one. Computer users are conditioned to seeing a prompt followed by a flashing cursor. Otherwise, if you ended the prompt string with a newline, the cursor would appear on the following line. That's okay, but it's not the way users expect prompts to present themselves.
* Even though two lines are displayed, you need only one %s placeholder in the printf() function to display the string. The newline is just a character; it doesn't split the string into two pieces.
Copyright © 1997-2025 by QPBC.
All rights reserved
