home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C by Discovery (4th Edition)
/
C_By_Discovery_4th_Edition.tar
/
C_By_Discovery_4th_Edition
/
_DISK_
/
ch7
/
struct.c
< prev
next >
Wrap
C/C++ Source or Header
|
2005-06-16
|
921b
|
34 lines
/* struct.c
*
* Synopsis - Declares and initializes a variable of type
* struct auto_part and displays its contents
* on the terminal screen.
*
* Objective - To illustrate declaring a structure and
* accessing its members.
*/
/* Include Files */
#include <stdio.h>
/* Constant Definitions */
#define ID_SIZE 8
/* Type Descriptions */
struct auto_part { /* Note 1 */
char id[ID_SIZE];
double price;
int cur_inv;
};
int main( void )
{
/* Note 2 */
struct auto_part part = { "J-145D", 4.79, 12 };
printf( "Part-id: %8s\n", part.id ); /* Note 3 */
printf( "Price : $%8.2f\n", part.price ); /* Note 3 */
printf( "Quantity: %8d\n", part.cur_inv ); /* Note 3 */
return 0;
}