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 >
C/C++ Source or Header  |  2005-06-16  |  921b  |  34 lines

  1. /*               struct.c
  2.  *
  3.  *   Synopsis  - Declares and initializes a variable of type 
  4.  *               struct auto_part and displays its contents 
  5.  *               on the terminal screen. 
  6.  *
  7.  *   Objective - To illustrate declaring a structure and
  8.  *               accessing its members.
  9.  */
  10.  
  11. /* Include Files */
  12. #include <stdio.h>
  13.  
  14. /* Constant Definitions */
  15. #define ID_SIZE 8
  16.  
  17. /* Type Descriptions */
  18. struct auto_part {                                  /* Note 1 */
  19.      char id[ID_SIZE];
  20.      double price;
  21.      int cur_inv;
  22. };
  23.  
  24. int main( void )
  25. {
  26.                                                     /* Note 2 */
  27.      struct auto_part part = { "J-145D", 4.79, 12 };
  28.  
  29.      printf( "Part-id:  %8s\n", part.id );          /* Note 3 */
  30.      printf( "Price :  $%8.2f\n", part.price );     /* Note 3 */
  31.      printf( "Quantity: %8d\n", part.cur_inv );     /* Note 3 */
  32.      return 0;
  33. }
  34.