Solution for Exercise 14-1

ex1401

#include <stdio.h>

int main()
{
    struct player
    {
        char name[32];
        int highscore;
    };
    struct player xbox;

    printf("Enter the player's name: ");
    scanf("%s",xbox.name);
    printf("Enter their high score: ");
    scanf("%d",&xbox.highscore);

    printf("Player %s has a high score of %d\n",
            xbox.name,xbox.highscore);
    return(0);
}

Notes

* There is no need to use a backslash at Line 17 to split the printf() function. For the printf() function, the comma is a natural separation between the formatting string and the variable list. The Enter at the end of the line and the Tabs at the start of Line 18 are all white space, which is ignored by the compiler. The net effect is that you can always split a printf() function between two lines in this manner. You could have also written it this way:

* The backslash is necessary only when you need to split text. What it does is escape the Enter key press at the end of a line, causing the compiler to ignore the break and treat two lines in your editor as a single line in the code.

* Actually, I broke Line 17's printf() statement in this code because of the book's page margins.

* Here's sample output: