SHARE
TWEET

Untitled

a guest Jun 12th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. struct misura {
  6.     int AAAA, MM, GG, hh, mm, ss, ms;
  7.     char ID[11];
  8.     double TEMP;
  9.     int UMID;
  10.     double VEL;
  11. };
  12. void leggi_misura(FILE *f, int *n, struct misura *lista);
  13. void stampa_riga(struct misura *lista, int i);
  14. void stampa_invertita(struct misura *lista, int n);
  15. double max_temp(struct misura *lista, int n);
  16.  
  17. int main(int argc, char *arcv[]) {
  18.     int n;
  19.     struct misura lista[168];
  20.     FILE *f;
  21.    
  22.     f = fopen("argv[1]", "r");
  23.    
  24.     leggi_misura(f, &n, lista);
  25.    
  26.     stampa_invertita(lista, n);
  27.    
  28.     double max = max_temp(lista, n);
  29.     printf("[MAX-TEMP]\n%lf\n", max);
  30.    
  31. }
  32.  
  33. void leggi_misura(FILE *f, int *n, struct misura *lista) {
  34.     char r[1000];
  35.     int i=0;
  36.    
  37.     while (fgets(r, sizeof(r), f)) {
  38.         int conv = sscanf(r, "%d-%d-%d %d:%d:%d.%d %s %lf %d%% %lf", &(lista[i].AAAA), &(lista[i].MM), &(lista[i].GG), &(lista[i].hh), &(lista[i].mm), &(lista[i].ss), &(lista[i].ms), (lista[i].ID), &(lista[i].TEMP), &(lista[i].UMID),  &(lista[i].VEL));
  39.         if (conv != 11) continue;
  40.         i++;
  41.         if (i>=168) break;
  42.         }
  43.     *n=i;    
  44. }
  45.  
  46. void stampa_riga(struct misura *lista, int i) {
  47.     printf("%d-%d-%d %d:%d:%d.%d %s %lf %d%% %lf\n", lista[i].AAAA, lista[i].MM, lista[i].GG, lista[i].hh, lista[i].mm, lista[i].ss, lista[i].ms, lista[i].ID, lista[i].TEMP, lista[i].UMID,  lista[i].VEL);
  48. }
  49.  
  50. void stampa_invertita(struct misura *lista, int n) {
  51.     int i;
  52.    
  53.     puts("[INVERTITA]");
  54.    
  55.     if (n < 6) {
  56.         for (i = n-1; i >= 0; i--) stampa_riga(lista, i);
  57.     }
  58.     else {
  59.         for (i=0; i<3; i++) stampa_riga(lista, i);
  60.         for (i=n-1; i>n-4; i--) stampa_riga(lista, i);
  61.     }
  62. }
  63.  
  64. double max_temp(struct misura *lista, int n) {
  65.     int i;
  66.     float max = lista[0].TEMP;
  67.    
  68.     for (i=1; i<n; i++) {
  69.         if (lista[i].TEMP > lista[0].TEMP)
  70.         max = lista[i].TEMP;
  71.     }
  72.     return max;
  73. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top