Solution for Exercise 7-12

ex0712

#include <stdio.h>

int main()
{
    char firstname[15];

    printf("Type your first name: ");
    scanf("%s",firstname);
    printf("Pleased to meet you, %s.\n",firstname);
    return(0);
}

Notes

* The string has storage for up to 15 characters, created at Line 5. That value is just a guess. In fact, this program could be considered insecure because there's no restriction put on the user from typing in more than 15 characters. Text beyond the 15th character would be stored, well, anywhere and potentially overwrite or corrupt other items in memory.

* The scanf() function reads in text up to the first white space character. If you type Billy Bob as your first name, input after the space is ignored, and the output shows only the text Billy.