Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char *argv[]){
  5.  
  6. FILE *sysFile;
  7. int data[100][4];
  8. int playercount[100][3];
  9. int gcount[15][2];
  10. int hcount[15][2];
  11. int fileWord;
  12. int counter = 0;
  13. int time,player,points;
  14. char team;
  15. int x = 0;
  16. int gpointCounter = 0;
  17. int hpointCounter = 0;
  18. int totalG = 0;
  19. int totalH = 0;
  20. int totalGOne = 0, totalGTwo = 0, totalGThree = 0, totalGFour = 0;
  21. int totalHOne = 0, totalHTwo = 0, totalHThree = 0, totalHFour = 0;
  22.  
  23. if(argc < 2){
  24. printf("Error: use %s filename to run program\n", argv[0]);
  25. exit(1);
  26. }
  27.  
  28. sysFile = fopen(argv[1], "r");
  29. if(sysFile == NULL){
  30. printf("Error: file %s not available\n", argv[1]);
  31. exit(1);
  32. }
  33.  
  34. for(int i = 0; i < 100; ++i){
  35. playercount[i][2] = 0;
  36. }
  37.  
  38. fscanf(sysFile, "%d %c %d %d", &time, &team, &player, &points);
  39. while ( !feof(sysFile) )
  40. {
  41. data[x][0] = time;
  42. data[x][1] = team;
  43. data[x][2] = player;
  44. data[x][3] = points;
  45.  
  46. printf("%d %c %d %d \n", data[x][0], data[x][1], data[x][2], data[x][3]);
  47.  
  48. if(data[x][0] < 600){
  49. if(data[x][1] == 'G'){
  50. gpointCounter += data[x][3];
  51. totalGOne += data[x][3];
  52. playercount[x][0] = 'G';
  53. playercount[x][1] = data[x][2];
  54. playercount[x][2] += data[x][3];
  55. printf("Player %d got %d points on team G 1/4\n", data[x][2], data[x][3]);
  56. // printf("total G points 1/4 = %d\n", gpointCounter);
  57. }else{
  58. hpointCounter += data[x][3];
  59. totalHOne += data[x][3];
  60. playercount[x][0] = 'H';
  61. playercount[x][1] = data[x][2];
  62. playercount[x][2] += data[x][3];
  63. printf("Player %d got %d points on team H 1/4\n", data[x][2], data[x][3]);
  64. // printf("total H points 1/4 = %d\n", hpointCounter);
  65. }
  66. // printf("Total 1/4 G = %d\n", gpointCounter);
  67. // printf("Total 1/4 H = %d\n", hpointCounter);
  68. }
  69.  
  70. if((data[x][0] > 600)&&(data[x][0] < 1200)){
  71. if(data[x][1] == 'G'){
  72. gpointCounter += data[x][3];
  73. totalGTwo += data[x][3];
  74. playercount[x][0] = 'G';
  75. playercount[x][1] = data[x][2];
  76. playercount[x][2] += data[x][3];
  77. printf("Player %d got %d points on team G 2/4\n", data[x][2], data[x][3]);
  78. // printf("total G points 2/4 = %d\n", gpointCounter);
  79. }else{
  80. hpointCounter += data[x][3];
  81. totalHTwo += data[x][3];
  82. playercount[x][0] = 'H';
  83. playercount[x][1] = data[x][2];
  84. playercount[x][2] += data[x][3];
  85. printf("Player %d got %d points on team H 2/4\n", data[x][2], data[x][3]);
  86. // printf("total H points 2/4 = %d\n", hpointCounter);
  87. }
  88. // printf("Total 2/4 G = %d\n", gpointCounter);
  89. // printf("Total 2/4 H = %d\n", hpointCounter);
  90. }
  91.  
  92. if((data[x][0] > 1200)&&(data[x][0] < 1800)){
  93. if(data[x][1] == 'G'){
  94. gpointCounter += data[x][3];
  95. totalGThree += data[x][3];
  96. playercount[x][0] = 'G';
  97. playercount[x][1] = data[x][2];
  98. playercount[x][2] += data[x][3];
  99. printf("Player %d got %d points on team G 3/4\n", data[x][2], data[x][3]);
  100. // printf("total G points 3/4 = %d\n", gpointCounter);
  101. }else{
  102. hpointCounter += data[x][3];
  103. totalHThree += data[x][3];
  104. playercount[x][0] = 'H';
  105. playercount[x][1] = data[x][2];
  106. playercount[x][2] += data[x][3];
  107. printf("Player %d got %d points on team H 3/4\n", data[x][2], data[x][3]);
  108. // printf("total H points 3/4 = %d\n", hpointCounter);
  109. }
  110. // printf("Total 3/4 G = %d\n", gpointCounter);
  111. // printf("Total 3/4 H = %d\n", hpointCounter);
  112. }
  113.  
  114. if((data[x][0] > 1800)&&(data[x][0] < 2400)){
  115. if(data[x][1] == 'G'){
  116. gpointCounter += data[x][3];
  117. totalGFour += data[x][3];
  118. playercount[x][0] = 'G';
  119. playercount[x][1] = data[x][2];
  120. playercount[x][2] += data[x][3];
  121. printf("Player %d got %d points on team G 4/4\n", data[x][2], data[x][3]);
  122. // printf("total G points 4/4 = %d\n", gpointCounter);
  123. }else{
  124. hpointCounter += data[x][3];
  125. totalHFour += data[x][3];
  126. playercount[x][0] = 'H';
  127. playercount[x][1] = data[x][2];
  128. playercount[x][2] += data[x][3];
  129. printf("Player %d got %d points on team H 4/4\n", data[x][2], data[x][3]);
  130. // printf("total H points 4/4 = %d\n", hpointCounter);
  131. }
  132. // printf("Total G = %d\n", gpointCounter);
  133. // printf("Total H = %d\n", hpointCounter);
  134. }
  135.  
  136. printf("\n");
  137.  
  138. x += 1;
  139.  
  140. fscanf(sysFile, "%d %c %d %d", &time, &team, &player, &points);
  141. }
  142.  
  143.  
  144. printf(" 1 2 3 4 total\n");
  145. printf("G: %02d %02d %02d %02d %02d\n", totalGOne, totalGTwo, totalGThree, totalGFour, gpointCounter);
  146. printf("h: %02d %02d %02d %02d %02d\n", totalHOne, totalHTwo, totalHThree, totalHFour, hpointCounter);
  147.  
  148. return 0;
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement