Advertisement
ebx

Izmjerene temperature

ebx
Jun 27th, 2011
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int main(int argc, char **argv)
  6. {
  7. FILE *fp;
  8. int **m, i, t;
  9. m=calloc(12, sizeof(int*));
  10. for (i=0; i<12; i++)
  11. m[i]=calloc(2, sizeof(int));
  12. fp=fopen("podaci.dat", "r");
  13. if (fp==NULL) return 0;
  14. else {
  15. printf("Otvorena!\n");
  16. while(!feof(fp)) {
  17. if (getc(fp)=='.') {
  18. fscanf(fp, "%d %d", &i, &t);
  19. m[i-1][0]++;
  20. m[i-1][1]+=t;
  21. }
  22. }
  23. }
  24. fclose(fp);
  25. printf("Zatvorena!\n");
  26. fp=fopen("obrada.txt", "w");
  27. if (fp==NULL) return 0;
  28. else {
  29. printf("Otvorena!\n");
  30. for (i=0; i<12; i++) {
  31. if (m[i][0]==0) fprintf(fp, "Nema mjerenja za %d. mjesec\n", i+1);
  32. else
  33. fprintf(fp, "%d. mjesec: %5.2f\n", i+1, (float)m[i][1]/m[i][0]);
  34. }
  35. }
  36. fclose(fp);
  37. printf("Zatvorena!\n");
  38. for (i=0; i<12; i++)
  39. free(m[i]);
  40. free(m);
  41. getchar();
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement