|
CS256 - Fundamentals of Structured Programming
| Displaying exercises/e8/solution/p3.c
#include <stdio.h>
#include <string.h>
#include <curses.h>
#define MAXLEN 1024
/**
* Re-use the getint() function from p2.c here:
*/
int getint(int y, int x, char *prompt)
{
int n, len = strlen(prompt);
mvprintw(y, x-len, prompt);
scanw("%d", &n);
return n;
}
/**
* Complete this function, it should work like getint() but read a string into
* the s parameter using the getnstr() function.
*/
void mygetstr(int y, int x, char *prompt, char s[])
{
int len = strlen(prompt);
mvprintw(y, x-len, prompt);
getnstr(s, MAXLEN);
}
int main(void)
{
/* Do not modify the code from here until the next comment: */
char s[MAXLEN];
initscr();
int x = getint(10, 10, "X? ");
int y = getint(11, 10, "Y? ");
mygetstr(12, 10, "Name? ", s);
/**
* Complete the program, clear the screen and print a "Hello, " followed by
* the name that was input at the location the user input. Then wait for
* the user to press a key to quit the program.
*/
clear();
mvprintw(y, x, "Hello, %s", s);
mvprintw(LINES-1, 0, "Press any key to exit");
refresh();
getch();
endwin();
return 0;
}
|