Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. /*Zadana je ulazna datoteka "utakmice.txt" s rezultatima sveučilišnog prvenstva u nogometu.
  2. Napisati program koji od korisnika traži da unese ime datoteke iz koje se učitavaju podaci. Na ekranu se ispisuje sadržaj datoteke i broj zapisa.
  3. Zatim se izračunava koliko je bodova osvojila ekipa hrv, ako se za pobjedu dobiva 3 boda, za neriješeno 1 bod, a za poraz 0 bodova.*/
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8.  
  9. #ifndef DEBUG
  10. #define DEBUG(...)printf(__VA_ARGS__)
  11. #endif
  12.  
  13. #ifndef INFILE
  14. #define INFILE "utakmice.txt"
  15. #endif
  16.  
  17. int main (){
  18. FILE *ulaz;
  19. int i, n=1, d, g, sum=0;
  20. char domaci[20], gosti[20];
  21. ulaz=fopen(INFILE, "r");
  22.  
  23. char c;
  24. c=fgetc(ulaz);
  25. while(c!=EOF){
  26. if(c=='\n'){
  27. n++;
  28. }
  29. c=fgetc(ulaz);
  30. }
  31. printf("\n%d redova\n", n);
  32.  
  33. rewind(ulaz);
  34.  
  35. for(i=0; i<n; i++){
  36. fscanf(ulaz, "%s %s %d %d", domaci, gosti, &d, &g);
  37. if(strcmp(domaci, "hrv")==0){
  38. if(d>g){
  39. sum=sum+3;
  40. }else if(d==g){
  41. sum=sum+1;
  42. }
  43. }else if(strcmp(gosti, "hrv")==0){
  44. if(d<g){
  45. sum=sum+3;
  46. }else if(d==g){
  47. sum=sum+1;
  48. }
  49. }
  50. }
  51.  
  52. printf("\n\nhrv im %d bodova", sum);
  53.  
  54.  
  55.  
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement