Witam serdecznie, męczę się z problemem, w którym nie mogę przejść pełną liczbę elementów struktury zagnieżdżonej w strukturze.
Może jaśniej:
Mam tak zdefiniowane struktury:
#include <stdio.h>
#include <stdlib.h>
/*----------------------------------------------------------------------------*/
struct Tutwor
{
char autor[30];
char wykonawca[30];
int czas;
};
struct Tinfcd
{
char tytul[50];
char nazwisko[20];
char nazwa[20];
int rok;
int cena;
struct Tutwor tab_tutwor[25];
};
Kolejno chce jak na razie uzupełnić 10elementową tablicę struktur Tinfcd (POLA TYLKO : rok, cena) oraz przejść i uzupełnić 25 elementową tablicę zagnieżdoną strutury Tutwor (POLE TYLKO : czas).
void wypelnij(struct Tinfcd tab_infcd[]);
void wyswietl(struct Tinfcd tab_infcd[]);
/*----------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
#define ROZMIAR 10
struct Tinfcd tab_infcd[ROZMIAR];
int zarodek=time(NULL);
srand(zarodek);
wypelnij(tab_infcd);
wyswietl(tab_infcd);
getche();
return 0;
}
/*----------------------------------------------------------------------------*/
void wypelnij(struct Tinfcd tab_infcd[])
{
int i,j;
for(i=0;i<ROZMIAR;i++)
{
tab_infcd[i].rok=rand()%50+1960;
tab_infcd[i].cena=rand()%50+20;
for(j=0;j<25;j++);
{
tab_infcd[i].tab_tutwor[j].czas=5;
}
}
}
/*----------------------------------------------------------------------------*/
void wyswietl(struct Tinfcd tab_infcd[])
{
int i,j;
for(i=0;i<ROZMIAR;i++)
{
printf("Rok wydania: %d.\n",tab_infcd[i].rok);
printf("Cena: %.2d PLN.\n",tab_infcd[i].cena);
for(j=0;j<25;j++);
{
printf("Czas: %d.\n",tab_infcd[i].tab_tutwor[j].czas);
}
printf("----------------------\n");
}
}
/*----------------------------------------------------------------------------*/
Program sie kompiluje, ale efektem jest przejście tylko 1 raz przez petle wewnetrzna for j=0;j<25;j++, a powinno byc 25 przejsc.
Nie wiem dlaczego, czy dobrze jest ta deklaracja struct Tutwor tab_tutwor[25];
?
Dziekuje za pomoc.