Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // polow.cpp : Defines the entry point for the console application.
- //
- #define _CRT_SECURE_NO_DEPRECATE
- #include "stdafx.h"
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <cstdio>
- #include <cstring>
- struct struct_ryby {
- char gatunek [20];
- float ilosc;
- };
- int _tmain(int argc, _TCHAR* argv[])
- {
- float c=0;
- int i=0;
- int z=0;
- int wynik;
- struct_ryby Ryby[100];
- FILE *wczytaj;
- FILE *zapisz;
- wczytaj = fopen ("wpolow.txt","r");
- if (NULL==wczytaj) {
- perror ("blad");
- exit (1);
- }
- while (!feof (wczytaj))
- {
- fscanf (wczytaj, "%s %f.5", &Ryby[i].gatunek, &Ryby[i].ilosc);
- printf ("%s , %f \n", Ryby[i].gatunek, Ryby[z].ilosc);
- for (int j=0;j<i;j++)
- {
- wynik = strcmp (Ryby[j].gatunek, Ryby[i].gatunek);
- printf ("\n j[%d] - %s i[%d] - %s \n\n",j,Ryby[j].gatunek,i, Ryby[i].gatunek);
- if (strcmp (Ryby[j].gatunek, Ryby[i].gatunek)== 0)
- {
- c=Ryby[i].ilosc;
- z=i;
- Ryby[z].ilosc = ((Ryby[i].ilosc) + (Ryby[j].ilosc));
- printf ("powtorzylem sie --> %s , %f , [%d] [%d] -----> %f + %f\n\n", Ryby[i].gatunek, Ryby[z].ilosc, i,z, c, Ryby[j].ilosc);
- (Ryby[j].ilosc) = 0;
- printf ("%d",Ryby[j].ilosc);
- }
- else
- {
- printf ("nie powtorzylem sie --> %s %f \n", Ryby[i].gatunek, Ryby[i].ilosc);
- }
- }
- z++;
- i++; //linczik
- }
- zapisz = fopen ("zpolow.txt","w");
- if (NULL==zapisz) {
- perror ("blad");
- fclose (wczytaj);
- exit (1);
- }
- for (int j=0; j<i; j++) {
- printf (" %s %f \n", Ryby[j].gatunek,Ryby[j].ilosc);
- if ((Ryby[j].ilosc) !=0)
- {
- fprintf (zapisz,"%s - %f.2 \n",Ryby[j].gatunek,Ryby[j].ilosc);
- }
- }
- fclose (wczytaj);
- fclose (zapisz);
- _getch();
- return 0;
- }
- /*
- makrela 5
- makrela 4
- losos 7.5
- okon 4.12
- tunczyk 6
- makrela 8
- okon 50
- krewetka 30
- dorsz 0
- */
Advertisement