Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //wczytywanie z pliku, zapis do pliku, struktura
- // ciezary.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <stdlib.h>
- #define _CRT_SECURE_NO_DEPRECATE
- float Waga[20];
- char Imie [20][20];
- int Powt[20];
- float Srednia[20];
- int _tmain(int argc, _TCHAR* argv[])
- {
- FILE *wczytaj;
- FILE *zapisz;
- int i=0;
- int porownanie=0;
- wczytaj = fopen ("wciezary.txt","r");
- if (wczytaj == NULL) {
- perror ("blad");
- exit(1);
- }
- while (!feof (wczytaj))
- {
- fscanf (wczytaj,"%s %f", &Imie[i], &Waga[i]);
- Powt[i] = 1;
- printf ("%s %.2f \n", Imie[i], Waga[i]);
- for (int j=0; j<i;j++)
- {
- porownanie = strcmp (Imie[i], Imie[j]);
- if (0 == porownanie)
- {
- Waga[j] = Waga[i] + Waga[j];
- Powt[j]++;
- i--;
- }
- }
- i++;
- }
- zapisz = fopen ("zciezary.txt","w");
- if (zapisz == NULL) {
- perror ("blad");
- fclose (wczytaj);
- exit (1);
- }
- for (int j=0; j<i;j++) {
- Srednia[j] = Waga[j] / Powt[j];
- printf ("%s podniosl srednio %.2f \n", Imie[j],Srednia[j]);
- fprintf (zapisz,"%s podniosl srednio %.2f \n", Imie[j],Srednia[j]);
- }
- _getch();
- return 0;
- }
- /* tak wyglada "wciezary.txt"
- Adam 10
- Adam 5
- Lukas 14
- Marcin 99
- Adam 7
- Marcin 53
- Wiktor 51
- Darek 3
- Wiktor 4
- Darek 5
- Darek 6
- */
Advertisement