Solution for Exercise 12-12

ex1212

#include <stdio.h>

int main()
{
    char firstname[16],lastname[16];

    printf("What is your first name? ");
    scanf("%15s",firstname);
    printf("What is your last name? ");
    scanf("%15s",lastname);
    printf("Pleased to meet you, %s %s\n",firstname,lastname);
    return(0);
}

Output

What is your first name? Morton
What is your last name? Boop
Please to meet you, Morton Boop

Notes

* Because scanf() terminates input at the first white space character, it won't read a first or last name that contains a space. That's one of the limitations of using scanf() for text input.

* If you type the enter name at the first prompt, output looks like this:

What is your first name? Morton Boop
What is your last name? Please to meet you, Morton Boop

This effect shows how streaming input is read, which is an important topic to understand in C.