Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. /* coding with phyvar 20110220 */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9.     int i = atoi(argv[2]);
  10.     int j = atoi(argv[1]);
  11.     FILE *tiedosto;
  12.     char tiedosto_nimi[10] = "mitta.dat";
  13.     int d, k, testi = 0;
  14.     char taulukko[i];
  15.  
  16.     struct taulu {
  17.         char paiva[64];
  18.         int arvo;
  19.     };
  20.  
  21.     struct taulu mittaus[j];
  22.  
  23.     if ((tiedosto = fopen(tiedosto_nimi, "r")) == NULL) {
  24.         printf("Tiedostoa ei löytynyt.");
  25.     }   else {
  26.         for(d = 0; d < j; d++) {
  27.             fgets(taulukko, i, tiedosto);
  28.                 strncpy(mittaus[d].paiva, taulukko, 63);
  29.             fgets(taulukko, i, tiedosto);
  30.                 mittaus[d].arvo = atoi(taulukko);
  31.             }
  32.         }
  33.  
  34.  
  35.     for (d = 0; d < i; d++) {
  36.         if (mittaus[d].arvo >= 0 && mittaus[d].arvo <= i) {
  37.             printf("%s ", mittaus[d].paiva);
  38.             printf("%d\n", mittaus[d].arvo);
  39.         }
  40.     }
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement