Source Code File 08-07_greetings

08-07_greetings.c

#include <ncurses.h>
   
int main()
{
    char first[32];
    char last[32];
    
    initscr();
    
    addstr("First name: ");
    getnstr(first,31);      
    addstr("Last name: ");
    getnstr(last,31);
    printw("Pleased to meet you, %s %s\n",
            first,
            last);
    refresh();
    getch();
        
    endwin();
    return(0);
}

Output Screenshot

Notes

* Yes, this code is similar to 08-01_yourname.c.

* In the book, Line 11 shows the getnstr() function's section argument as 32, which is the same as the size of buffer first. This size is too large, as the newline added to a 32-character string would overflow the buffer. This change has been made to the source code file above as well as in the archive.