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

  1. /* AGENTS.C - From "Microsoft C Programming for the IBM, page   */
  2. /* 300, by Robert Lafore. The program uses an array of struct-  */
  3. /* ures to maintain a list of agents in memory. It is also a    */
  4. /* continuation of the development of a simple database started */
  5. /* on page 292.                                                 */
  6. /****************************************************************/
  7.  
  8. #include <stdio.h>
  9. #define TRUE 1
  10.  
  11. struct personnel {
  12.    char name [30];
  13.    int agnumb;
  14.    float height;
  15. };
  16. struct personnel agent[50];      /*array of 50 structures*/
  17. int n = 0;
  18.  
  19. main()
  20. {
  21. char ch;
  22.  
  23.    while(TRUE) {
  24.       printf("\nType 'e' to enter new agent");
  25.       printf("\n  'L' to list all agents: ");
  26.       ch = getche();
  27.       switch (ch) {
  28.          case 'e':
  29.             newname();
  30.             break;
  31.          case 'L':
  32.             listall();
  33.             break;
  34.          default:
  35.             puts("\nEnter only selections listed");
  36.       }
  37.    }
  38. }
  39.  
  40. /* newname */
  41. /* puts a new agent in the database */
  42. newname()
  43. {
  44.    printf("\nRecord %d: \nEnter name: ", n + 1);
  45.    gets(agent[n].name);
  46.    printf("Enter agent number (3 digits): ");
  47.    scanf("%d", &agent[n].agnumb);
  48.    printf("Enter height in inches: ");
  49.    scanf("%f", &agent[n++].height);
  50.    fflush(stdin);
  51. }
  52.  
  53. /* listall() */
  54. /* lists all agents and data */
  55. listall()
  56. {
  57. int j;
  58.  
  59.    if (n < 1)
  60.       printf("\nEmpty list.\n");
  61.    for(j = 0; j < n; j++) {
  62.       printf("\nRecord number %d\n", j + 1);
  63.       printf("   Name: %s\n", agent[j].name);
  64.       printf("   Agent number: %03d\n", agent[j].agnumb);
  65.       printf("   Height: %4.2f\n", agent[j].height);
  66.    }
  67. }
  68.  
  69.