Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Zadana je ulazna datoteka "utakmice.txt" s rezultatima sveučilišnog prvenstva u nogometu.
- 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.
- 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.*/
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #ifndef DEBUG
- #define DEBUG(...)printf(__VA_ARGS__)
- #endif
- #ifndef INFILE
- #define INFILE "utakmice.txt"
- #endif
- int main (){
- FILE *ulaz;
- int i, n=1, d, g, sum=0;
- char domaci[20], gosti[20];
- ulaz=fopen(INFILE, "r");
- char c;
- c=fgetc(ulaz);
- while(c!=EOF){
- if(c=='\n'){
- n++;
- }
- c=fgetc(ulaz);
- }
- printf("\n%d redova\n", n);
- rewind(ulaz);
- for(i=0; i<n; i++){
- fscanf(ulaz, "%s %s %d %d", domaci, gosti, &d, &g);
- if(strcmp(domaci, "hrv")==0){
- if(d>g){
- sum=sum+3;
- }else if(d==g){
- sum=sum+1;
- }
- }else if(strcmp(gosti, "hrv")==0){
- if(d<g){
- sum=sum+3;
- }else if(d==g){
- sum=sum+1;
- }
- }
- }
- printf("\n\nhrv im %d bodova", sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement