Passing a structure to a function. - C Structure

C examples for Structure:Structure Value

Description

Passing a structure to a function.

Demo Code

#include <stdio.h>

struct data {/*from   ww  w  . ja  v a 2 s  . c  om*/
    float amount;
    char fname[30];
    char lname[30];
} rec;

void print_rec(struct data displayRec)
{
    printf("\nDonor %s %s gave $%.2f.\n", displayRec.fname,
            displayRec.lname, displayRec.amount);
}


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

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

    print_rec( rec );

    return 0;
}

Result


Related Tutorials