home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tyc
/
list11_5.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-16
|
883b
|
39 lines
/* Demonstrates passing a structure to a function. */
#include <stdio.h>
/* Declare and define a structure to hold the data. */
struct data{
float amount;
char fname[30];
char lname[30];
} rec;
/* The function prototype. The function has no return value, */
/* and it takes a structure of type data as its one argument. */
void print_rec(struct data x);
main()
{
/* 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);
/* Call the display function. */
print_rec( rec );
}
void print_rec(struct data x)
{
printf("\nDonor %s %s gave $%.2f.", x.fname, x.lname,
x.amount);
}