Solution for Exercise 15-6
ex1506 - Windows Solution
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Press Enter to clear the screen:");
getchar();
system("cls");
puts("That's better");
return(0);
}
Output
Press Enter to clear the screen:
(Enter is pressed. The screen clears.)
That's better
Notes
* The getchar() function is used here merely to pause the program. Its return value isn't used or needed.
ex1506 - Mac/Unix Solution
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("Press Enter to clear the screen:");
getchar();
system("clear");
puts("That's better");
return(0);
}
Output
Press Enter to clear the screen:
(Enter is pressed. The screen clears.)
That's better
Notes
* Refer to the Notes for the Windows version of this code.
Copyright © 1997-2025 by QPBC.
All rights reserved
