Advertisement
Perlamado

Untitled

Feb 20th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. // esame 03-03-2014
  2. //file030314.txt
  3. 85445.23
  4. 244
  5. 2 -25792.36
  6. 4 -2894.49
  7. 6 -19672.86
  8. 7 12520.53
  9. 9 30428.5
  10. 10 1359.15
  11. 12 -32579.95
  12. 13 2079.01
  13. 15 -34461.13
  14. 16 -30321.04
  15. 17 13074.09
  16. 19 30130.55
  17. 21 1885.01
  18. 22 10774.33
  19. 23 14083.34
  20. 25 18353.86
  21. 26 -31677.48
  22. 28 -12023.6
  23. 30 17948.73
  24. 32 -9426.29
  25. 33 33778.52
  26. 35 17734.91
  27. 37 -29911.99
  28. 39 26929.5
  29. 40 -4451.2
  30. 42 -1558.78
  31. 43 -15756.52
  32. 44 -23344.5
  33. 45 27835.94
  34. 47 -30760.5
  35. 49 316.6
  36. 51 -12667.69
  37. 53 -421.63
  38. 54 -28648.7
  39. 56 -29837.56
  40. 58 -8110.05
  41. 59 28967.22
  42. 61 -2488.79
  43. 63 -31494.12
  44. 65 18914.32
  45. 67 -26224.42
  46. 68 13191.87
  47. 70 9068.04
  48. 72 15778.84
  49. 74 27200.05
  50. 75 -13557.47
  51. 76 929.16
  52. 78 24218.71
  53. 79 23905.74
  54. 80 -5922.38
  55. 82 -2245.78
  56. 83 -22517.06
  57. 84 5015.84
  58. 86 -32686.24
  59. 88 -106.39
  60. 90 17380.49
  61. 92 27351.62
  62. 94 23942.77
  63. 95 -20107.39
  64. 97 -25870.09
  65. 98 -15778.83
  66. 99 -5999.47
  67. #include <stdio.h>
  68. #include <string.h>
  69. #include <stdlib.h>
  70. #include <math.h> //-lm
  71.  
  72. struct conto{
  73. double saldoI;
  74. int totM; // tot movimenti
  75. int data;
  76. double movimenti;
  77.  
  78. };
  79. struct conto *letturaFile(FILE *f,int *n);
  80. void stampaStruttura(struct conto *c,int n);
  81.  
  82. int main(int argc, char *argv[]){
  83.  
  84. int n;
  85. FILE *f;
  86. struct conto *conto;
  87.  
  88. if(argc!=2){
  89. printf("parametri errati\n");
  90. return 1;
  91. }
  92. f=fopen(argv[1],"r");
  93. if(f==NULL){
  94. printf("file non trovato\n");
  95. return 1;
  96. }
  97.  
  98. //funzioni lettura e stampa
  99. conto=letturaFile(f,&n);
  100. fclose(f);
  101. stampaStruttura(conto,n);
  102. return 0;
  103. }
  104.  
  105. struct conto *letturaFile(FILE*f,int *n){
  106. int nConv;
  107. int size=10;
  108. char buffer[100];
  109. struct conto *c1,*c2;
  110. *n=0;
  111.  
  112. c2=malloc(size*sizeof(struct conto));
  113.  
  114. while(fgets(buffer,sizeof(buffer),f)){
  115.  
  116. c1=c2 + *n;
  117. nConv=sscanf(buffer,"%d\t%lf\t",&c1->data,&c1->movimenti);
  118. if (nConv==1){
  119.  
  120. }
  121. (*n)++;
  122. if(*n>=size){
  123. size=2*size;
  124. c2=realloc(c2,size*sizeof(struct conto));
  125. }
  126. }
  127. c2=realloc(c2,*n*sizeof(struct conto));
  128. return c2;
  129. }
  130.  
  131. void stampaStruttura(struct conto *c,int n){
  132. int i;
  133. for(i=0;i<n;i++){
  134. printf( "%d %lf\n",c[i].data,c[i].movimenti);
  135. }
  136. }
  137. /*double saldoFinale(struct conto *c,int n){
  138.  
  139. int i;
  140. double count=0;
  141. for(i=0;i<n;i++){
  142. count+=c[i].movimenti;
  143. return count;
  144.  
  145. }
  146.  
  147. } */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement