Solution for Exercise 13-10

ex1310

#include <stdio.h>
#include <string.h>

int main()
{
    char first[40];
    char last[20];

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

Output

What is your first name? Danny
What is your last name? Gookin
Pleased to meet you, Danny Gookin!

Notes

* To solve the puzzle by using the strcat() function, you must tack the extra space onto the first string before you add on the last string.

* Though the space is a single character, it's specified with double quotes to ensure that the compiler treats it as a string (in Line 13).