Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, char **argv)
- {
- FILE *fp;
- int **m, i, t;
- m=calloc(12, sizeof(int*));
- for (i=0; i<12; i++)
- m[i]=calloc(2, sizeof(int));
- fp=fopen("podaci.dat", "r");
- if (fp==NULL) return 0;
- else {
- printf("Otvorena!\n");
- while(!feof(fp)) {
- if (getc(fp)=='.') {
- fscanf(fp, "%d %d", &i, &t);
- m[i-1][0]++;
- m[i-1][1]+=t;
- }
- }
- }
- fclose(fp);
- printf("Zatvorena!\n");
- fp=fopen("obrada.txt", "w");
- if (fp==NULL) return 0;
- else {
- printf("Otvorena!\n");
- for (i=0; i<12; i++) {
- if (m[i][0]==0) fprintf(fp, "Nema mjerenja za %d. mjesec\n", i+1);
- else
- fprintf(fp, "%d. mjesec: %5.2f\n", i+1, (float)m[i][1]/m[i][0]);
- }
- }
- fclose(fp);
- printf("Zatvorena!\n");
- for (i=0; i<12; i++)
- free(m[i]);
- free(m);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement