Hejka. Chciałabym się Was zapytać, czy coś jest nie tak w kodzie, że program po zapisaniu danych do pliku, po otwarciu go posiada takie coś? "l_v°@ Ě˙a 124 0.000000"
Kod jest na tą chwilę następujący:
#include <stdlib.h>
#include <stdio.h>
#define PLIK "plik.txt"
typedef struct
{
char nazwisko[20], imie[20];
int rok_ur;
float srednia;
} TDane;
typedef struct
{
TDane d;
struct TElement* next;
} TElement;
typedef TElement* TWsk;
int WprowadzStudenta(TDane *x);
int WyswietlStudenta(TDane x);
int NaStos(TWsk *P, TDane x);
int ZeStosu(TWsk *P, TDane *x);
int WprowadzDane(TWsk *P);
int UsunStos(TWsk *P);
int WyswietlStos(TWsk P);
float ZwrocSrednia(TWsk P);
int NajwiekszyElement(TWsk P);
int main()
{
FILE *pliczek;
TDane x;
TWsk P;
P=NULL;
WprowadzDane(&P);
printf("\nWprowadzono nastepujace dane: \n");
printf("Srednia: %.2f\n", ZwrocSrednia(P));
printf("Najwiekszy element: %d\n", NajwiekszyElement(P));
UsunStos(&P);
pliczek = fopen(PLIK, "w");
fprintf(pliczek, "%s %s %d %f", x.imie, x.nazwisko, x.rok_ur, x.srednia);
fclose(pliczek);
return 0;
}
int WprowadzStudenta(TDane *x)
{
printf("Podaj nazwisko: ");
scanf("%s", x->nazwisko);
printf("Podaj imie: ");
scanf("%s", x->imie);
printf("Podaj rok urodzenia: ");
scanf("%d", &x->rok_ur);
printf("Podaj srednia: ");
scanf("%f", &x->srednia);
return 0;
}
int WyswietlStudenta(TDane x)
{
printf("%s %s %d %4.2f\n", x.nazwisko, x.imie, x.rok_ur, x.srednia);
return 0;
}
int NaStos(TWsk *P, TDane x)
{
TWsk Q;
Q=(TElement*)malloc(sizeof(TElement));
Q->d=x;
Q->next=(*P);
(*P)=Q;
return 0;
}
int ZeStosu(TWsk *P, TDane *x)
{
TWsk Q;
if(P!=NULL)
{
Q=(*P);
*x=Q->d;
(*P)=Q->next;
free(Q);
}
return 0;
}
int WprowadzDane(TWsk *P)
{
int n, i;
TDane x;
printf("Dane ilu osob chcesz wprowadzic?: ");
scanf("%d", &n);
for(i=1; i<=n; i++)
{
printf("%d osoba: \n", i);
WprowadzStudenta(&x);
NaStos(&(*P), x);
}
return 0;
}
int UsunStos(TWsk *P)
{
TDane x;
while((*P)!=NULL)
{
ZeStosu(&(*P), &x);
WyswietlStudenta(x);
}
return 0;
}
int WyswietlStos(TWsk P)
{
while (P!=NULL)
{
WyswietlStudenta(P->d);
P=P->next;
}
return 0;
}
float ZwrocSrednia(TWsk P)
{
float sum_srednia = 0.f;
int ilosc = 0;
while(P!= NULL){
sum_srednia += P->d.srednia;
++ilosc;
P = P->next;
}
if( ilosc == 0)
return 0.f;
return sum_srednia/ilosc;
}
int NajwiekszyElement(TWsk P)
{
int najwiekszy = 0;
int ile = 0;
while(P!=NULL)
{
if(P->d.rok_ur>najwiekszy)
najwiekszy = P->d.rok_ur;
++ile;
P = P->next;
}
if(ile==0)
{
printf("Brak najwiekszego elementu!");
return 0;
}
return najwiekszy;
}
Byłabym bardzo wdzięczna za pomoc. :)