home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 7.img / EXAMPLES.ZIP / PLOTEMP2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-04  |  2.1 KB  |  101 lines

  1. /* PLOTEMP2.C--Example from Chapter 7 of Getting Started */
  2.  
  3. /* This program creates a table and a bar chart plot from a
  4.    set of temperature readings */
  5.  
  6. #include <conio.h>
  7. #include <ctype.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. /* Prototypes */
  12.  
  13. void get_temps(void);
  14. void table_view(void);
  15. void min_max(void);
  16. void avg_temp(void);
  17. void graph_view(void);
  18. void save_temps(void);
  19. void read_temps(void);
  20.  
  21. /* Global defines */
  22.  
  23. #define TRUE      1
  24. #define READINGS  8
  25.  
  26. /* Global data structures */
  27.  
  28. int temps[READINGS];
  29. int main(void)
  30. {
  31.    while (TRUE)
  32.    {
  33.       printf("\nTemperature Plotting Program Menu\n");
  34.       printf("\tE - Enter temperatures for scratchpad\n");
  35.       printf("\tS - Store scratchpad to disk\n");
  36.       printf("\tR - Read disk file to scratchpad\n");
  37.       printf("\tT - Table view of current data\n");
  38.       printf("\tG - Graph view of current data\n");
  39.       printf("\tX - Exit the program\n");
  40.       printf("\nPress one of the above keys: ");
  41.  
  42.       switch (toupper(getche()))
  43.       {
  44.      case 'E': get_temps();  break;
  45.      case 'S': save_temps(); break;
  46.      case 'R': read_temps(); break;
  47.      case 'T': table_view(); break;
  48.      case 'G': graph_view(); break;
  49.      case 'X': exit(0);
  50.       }
  51.    }
  52. }
  53.  
  54. /* Function definitions */
  55. void get_temps(void)
  56. {
  57.    char inbuf[130];
  58.    int  reading;
  59.  
  60.    printf("\nEnter temperatures, one at a time.\n");
  61.    for (reading = 0; reading < READINGS; reading++)
  62.    {
  63.       printf("\nEnter reading # %d: ", reading + 1);
  64.       gets(inbuf);
  65.       sscanf(inbuf, "%d", temps[reading]);
  66.  
  67.       /* Show what was read */
  68.       printf("\nRead temps[%d] = %d", reading, temps[reading]);
  69.    }
  70. }
  71.  
  72. void table_view(void)
  73. {
  74.    printf("\nExecuting table_view().\n");
  75. }
  76.  
  77. void min_max(void)
  78. {
  79.    printf("\nExecuting min_max().\n");
  80. }
  81.  
  82. void avg_temp(void)
  83. {
  84.    printf("\nExecuting avg_temp().\n");
  85. }
  86.  
  87. void graph_view(void)
  88. {
  89.    printf("\nExecuting graph_view().\n");
  90. }
  91.  
  92. void save_temps(void)
  93. {
  94.    printf("\nExecuting save_temps().\n");
  95. }
  96.  
  97. void read_temps(void)
  98. {
  99.    printf("\nExecuting read_temps().\n");
  100. }
  101.