array.c

来自「c21Examples.rar」· C语言 代码 · 共 38 行

C
38
字号
/* Demonstrates a structure that has array members. */

#include <stdio.h>

/* Define and declare a structure to hold the data. */
/* It contains one float variable and two char arrays. */

struct data{
    float amount;
    char fname[30];
    char lname[30];
} rec;

int main( void )
{
    /* Input the data from the keyboard. */

    printf("Enter the donor's first and last names,\n");
    printf("separated by a space: ");
    scanf("%s %s", rec.fname, rec.lname);

    printf("\nEnter the donation amount: ");
    scanf("%f", &rec.amount);

    /* Display the information. */
    /* Note: %.2f specifies a floating-point value */
    /* to be displayed with two digits to the right */
    /* of the decimal point. */

    /* Display the data on the screen. */

    printf("\nDonor %s %s gave $%.2f.\n", rec.fname, rec.lname,
            rec.amount);

    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?