From the course: Exploring C Libraries
Unlock this course with a free trial
Join today to access over 25,600 courses taught by industry experts.
Solution: Fill the screen - C Tutorial
From the course: Exploring C Libraries
Solution: Fill the screen
(bright music) - [Instructor] Here's my solution, which follows the general pattern of an ncurses program. The standard screen is initialized. The getmaxyx function returns the height and width of the standard screen. The printw function outputs the prompt to instruct the user, and most importantly, the refresh function is issued so that the user sees the screen's updated information. The core of the program is this while loop. It spins as long as the value of variable key isn't equal to the tilde. Now, key is an integer variable, but it can also be declared as a chtype, which is the ncurses-combined character and attribute data type. I initialized the variable here so that the loop starts. Otherwise, the program may quit prematurely. A new value for key is fetched from the keyboard here, then a nested loop fills the screen going by row and then column using the values returned from the getmaxyx function earlier in the code. The mvaddch function relocates the cursor to the given…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.