Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // operacje na plikach, struktura
- // Miasta.cpp : Defines the entry point for the console application.
- //
- #define _CRT_SECURE_NO_DEPRECATE
- #include "stdafx.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include <conio.h>
- #include <cstdio>
- #include <string.h>
- struct struct_Miasto
- {
- char nazwa[100];
- float opady;
- int numer;
- };
- int _tmain(int argc, _TCHAR* argv[])
- {
- char porownanie;
- int i=0;
- struct_Miasto Miasto [100];
- FILE *wczytaj;
- FILE *zapisz;
- wczytaj = fopen ("wopady.txt","r");
- if (NULL==wczytaj)
- {
- perror ("blad");
- exit (1);
- }
- while (!feof (wczytaj)) {
- fscanf (wczytaj," %s %f", &Miasto[i].nazwa, &Miasto[i].opady);
- printf ("%s %.2f \n",Miasto[i].nazwa, Miasto[i].opady);
- for (int j=0;j<i;j++)
- {
- porownanie = strcmp (Miasto[i].nazwa, Miasto[j].nazwa);
- if (0 == porownanie)
- {
- if ((Miasto[i].opady) >= (Miasto[j].opady))
- {
- Miasto[j].opady = Miasto[i].opady;
- }
- i--;
- }
- } // for
- i++;
- }
- zapisz = fopen ("zopady.txt","w");
- if (zapisz == NULL )
- {
- perror ("blad");
- fclose (wczytaj);
- exit (1);
- }
- for (int j=0; j<i; j++)
- {
- fprintf (zapisz,"%s %.2f \n", Miasto[j].nazwa,Miasto[j].opady);
- printf ("zapisalem %s %.2f \n", Miasto[j].nazwa,Miasto[j].opady);
- }
- fclose (zapisz);
- fclose (wczytaj);
- _getch ();
- return 0;
- }
- /* tak wygalda plik "wopady.txt"
- Katowice 2.02
- Gliwice 1.5
- Bytom 5.5
- Zabrze 4
- Katowice 4.4
- Bytom 1.5
- Gliwcie 7
- Bytom 1.23
- Bytom 9.2
- */
Advertisement