Source Code File 02-07_yourname

02-07_yourname.c

#include <ncurses.h>
   
int main()
{
    char first[24];
    char last[32];

    initscr();
    addstr("What is your first name? ");
    refresh();
    getnstr(first,23);
    
    addstr("What is your last name? ");
    refresh();
    getnstr(last,31);
    
    printw("Pleased to meet you, %s %s!",first,last);
    refresh();
    getch();
    
    endwin();
    return(0);
}

Output Screenshot

Notes

* The second argument for getnstr() must be one less than the buffer size. This difference accounts for the null character, \0, at the end of a string.