home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / R_LA4_01.ZIP / PASSTWO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-12-21  |  1.5 KB  |  51 lines

  1. /*PASSTWO.C - From page 298 of "Microsoft C Programming for the */
  2. /* IBM" by Robert Lafore. This program demonstrates that the    */
  3. /* value of a structure variable can be passed to a function as */
  4. /* a parameter. Also a continuation of simple database started  */
  5. /* on page 292.                                                 */
  6. /****************************************************************/
  7.  
  8. #include <stdio.h>
  9.  
  10. struct personnel {            /*define data structure*/
  11.    char name [30];
  12.    int agnumb;
  13. };
  14.  
  15. main()
  16. {
  17. struct personnel agent1;      /*declare structure variable*/
  18. struct personnel agent2;      /*declare structure variable*/
  19. struct personnel newname();   /*declare function*/
  20.  
  21.    agent1 = newname();        /*get data for 1st agent*/
  22.    agent2 = newname();        /*get data for 2nd agent*/
  23.    list(agent1);              /*print data for 1st agent*/
  24.    list(agent2);              /*print data for 2nd agent*/
  25. }
  26.  
  27. /* newname() */
  28. /* puts a new agent in the database */
  29. struct personnel newname()
  30. {
  31. struct personnel agent;             /*new structure*/
  32.  
  33.    printf("\nNew agent\nEnter name: ");
  34.    gets(agent.name);
  35.    printf("Enter agent number (3 digits): ");
  36.    scanf("%d",&agent.agnumb);
  37.    fflush(stdin);
  38.    return(agent);
  39. }
  40.  
  41. /* list() */
  42. /* prints data on one agent */
  43. list(age)
  44. struct personnel age;               /*struct passed from main*/
  45. {
  46.    printf("\n\nAgent: \n");
  47.    printf("   Name: %s\n", age.name);
  48.    printf("   Agent number: %03d\n", age.agnumb);
  49. }
  50.  
  51.