Witam,
mógłby mi ktoś wytłumaczyć co jest nie tak z funkcją "wyswietlPostacie" ?
Nie za bardzo jeszcze rozumiem odwołania między strukturami robię to wszystko metodą prób i błędów.
#include <stdio.h>
#include <stdlib.h>
#define MAX_NAZWA 10
struct Data // STRUKTURY
{
int dzien;
int miesiac;
int rok;
};
struct Postac
{
char nazwa[ MAX_NAZWA ];
int sila;
int zrecznosc;
struct Data data_utworzenia;
int szybkosc;
int id_gracza;
};
struct Postacie
{
struct Postac postacie[20];
int liczba_postaci;
};
void wczytajPostacie(struct Postacie *postacie);
void wczytajPostac(struct Postac *postac) ;
float obliczSredniaSzybkosc(struct Postacie * postacie );
void wyswietlPostacie(struct Postacie postacie );
void obliczMaxMinSzybkosc(struct Postacie * postacie, int * max, int * min )
{
int i;
* max = postacie->postacie[0].szybkosc;
* min = postacie->postacie[0].szybkosc;
for(i=1; i < postacie->liczba_postaci; ++i)
{
if (postacie->postacie[i].szybkosc > * max)
* max = postacie->postacie[i].szybkosc;
if (postacie->postacie[i].szybkosc < * min)
* min = postacie->postacie[i].szybkosc;
}
}
int main()
{
struct Postacie postacie;
wczytajPostacie(&postacie);
int maxSzybkosc, minSzybkosc;
obliczMaxMinSzybkosc(&postacie, & maxSzybkosc, & minSzybkosc);
printf("Maksymalna szybkosc: %d\n", maxSzybkosc);
printf("Minimalna szybkosc: %d\n", minSzybkosc);
wyswietlPostacie( postacie );
return 0;
}
void wczytajPostacie(struct Postacie *postacie)
{
printf( "Podaj liczbe postaci:");
scanf( "%d", & (postacie->liczba_postaci) );
for( int i = 0; i < postacie->liczba_postaci; ++i )
wczytajPostac(& (postacie->postacie[i]) );
}
void wczytajPostac(struct Postac *postac)
{
printf("Wczytywanie postaci\n");
printf( "\tnazwa:");
scanf( "%s", postac->nazwa);
printf( "\tsila:");
scanf( "%d", &postac->sila);
printf( "\tzrecznosc:");
scanf( "%d", &postac->zrecznosc);
printf( "\tszybkosc:");
scanf( "%d", & (postac->szybkosc));
printf( "\tID gracza:");
scanf( "%d", & (postac->id_gracza));
}
float obliczSredniaSzybkosc(struct Postacie * postacie )
{
int suma = 0;
for (int i=0; i < postacie->liczba_postaci; ++i)
{
suma += postacie->postacie[i].szybkosc;
}
return (float)suma/(float)(postacie->liczba_postaci);
}
void wyswietlPostacie(struct Postacie postacie)
{
for (int i=0; i < Postac.postacie->liczba_postaci; ++i)
{
printf("Postac[%d] %s",i,Postac.nazwa);
printf("\tSila %d",&Postac.sila);
printf("\tZrecznosc %d",&Postac.zrecznosc);
printf("\tSzybkosc %d",&Postac.szybkosc);
printf("\tID gracza %d",&Postac.id_gracza);
}
// praca domowa wyœwietliæ dane
// w pêtli wywo³aæ funkcjê wyswietlPostac( struct Postac postac)
}
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
|In function 'wyswietlPostacie':|
118|error: 'Postac' undeclared (first use in this function)|
118|note: each undeclared identifier is reported only once for each function it appears in|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|