Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // esame 03-03-2014
- //file030314.txt
- 85445.23
- 244
- 2 -25792.36
- 4 -2894.49
- 6 -19672.86
- 7 12520.53
- 9 30428.5
- 10 1359.15
- 12 -32579.95
- 13 2079.01
- 15 -34461.13
- 16 -30321.04
- 17 13074.09
- 19 30130.55
- 21 1885.01
- 22 10774.33
- 23 14083.34
- 25 18353.86
- 26 -31677.48
- 28 -12023.6
- 30 17948.73
- 32 -9426.29
- 33 33778.52
- 35 17734.91
- 37 -29911.99
- 39 26929.5
- 40 -4451.2
- 42 -1558.78
- 43 -15756.52
- 44 -23344.5
- 45 27835.94
- 47 -30760.5
- 49 316.6
- 51 -12667.69
- 53 -421.63
- 54 -28648.7
- 56 -29837.56
- 58 -8110.05
- 59 28967.22
- 61 -2488.79
- 63 -31494.12
- 65 18914.32
- 67 -26224.42
- 68 13191.87
- 70 9068.04
- 72 15778.84
- 74 27200.05
- 75 -13557.47
- 76 929.16
- 78 24218.71
- 79 23905.74
- 80 -5922.38
- 82 -2245.78
- 83 -22517.06
- 84 5015.84
- 86 -32686.24
- 88 -106.39
- 90 17380.49
- 92 27351.62
- 94 23942.77
- 95 -20107.39
- 97 -25870.09
- 98 -15778.83
- 99 -5999.47
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <math.h> //-lm
- struct conto{
- double saldoI;
- int totM; // tot movimenti
- int data;
- double movimenti;
- };
- struct conto *letturaFile(FILE *f,int *n);
- void stampaStruttura(struct conto *c,int n);
- int main(int argc, char *argv[]){
- int n;
- FILE *f;
- struct conto *conto;
- if(argc!=2){
- printf("parametri errati\n");
- return 1;
- }
- f=fopen(argv[1],"r");
- if(f==NULL){
- printf("file non trovato\n");
- return 1;
- }
- //funzioni lettura e stampa
- conto=letturaFile(f,&n);
- fclose(f);
- stampaStruttura(conto,n);
- return 0;
- }
- struct conto *letturaFile(FILE*f,int *n){
- int nConv;
- int size=10;
- char buffer[100];
- struct conto *c1,*c2;
- *n=0;
- c2=malloc(size*sizeof(struct conto));
- while(fgets(buffer,sizeof(buffer),f)){
- c1=c2 + *n;
- nConv=sscanf(buffer,"%d\t%lf\t",&c1->data,&c1->movimenti);
- if (nConv==1){
- }
- (*n)++;
- if(*n>=size){
- size=2*size;
- c2=realloc(c2,size*sizeof(struct conto));
- }
- }
- c2=realloc(c2,*n*sizeof(struct conto));
- return c2;
- }
- void stampaStruttura(struct conto *c,int n){
- int i;
- for(i=0;i<n;i++){
- printf( "%d %lf\n",c[i].data,c[i].movimenti);
- }
- }
- /*double saldoFinale(struct conto *c,int n){
- int i;
- double count=0;
- for(i=0;i<n;i++){
- count+=c[i].movimenti;
- return count;
- }
- } */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement