我有一个问题,我有一个函数,它填充了一个结构体的几个方面,但它给了我一个错误,说它已经被声明了不止一次,使用不同类型的参数,但我找不到问题。一些变量和函数名是西班牙语的。
struct juegos_interano {
char participantes[60][15];
char sexo[60];
int medallas[10][4];
char deportes_partisipados[60][10];
char encargado[20];
int max_persona;
};
struct todos_los_anos {
struct juegos_interano primer_ano;
struct juegos_interano segundo_ano;
struct juegos_interano tercer_ano;
struct juegos_interano cuarto_ano;
};
struct todos_los_anos create_random_table()
{
srand(time(NULL));
struct todos_los_anos all_year;
//200 names
char names[200][20] = {
"Juan", "Pedro", "Luis" };
//Sex in relation to names
char sex[200] = {
'M', 'M', 'M' };
char sports[10] = {'n','v','b','t','f','y','k','d','a','p'};
int medals[40] = {1};
int medallas = 40;
int rand_total_name = 0;
int rand_total_medallas = 0;
int rand_name = 0;
int rand_sport = 0;
int rand_medals = 0;
int random = 0;
int r_name = 0;
int i = 0;
rand_total_name = rand() % 60 +20;
rand_total_medallas = rand() % medallas;
medallas = medallas - rand_total_medallas;
rand_name = 0;
rand_sport = 0;
rand_medals = 0;
random = 0;
i = 0;
for (i=0; i < rand_total_name; i++)
rand_name = rand() % 200;
rand_sport = rand() % 10;
random = rand() % rand_sport;
rand_medals = rand_medals - random;
if (rand_medals<0)
random = random + rand_medals;
fill_struct (&all_year.primer_ano, rand_total_name, rand_name, rand_sport, random, rand_total_medallas, i, names, sex, sports, medals);
r_name = rand() % 200;
strcpy(all_year.primer_ano.encargado, names[r_name]);
rand_total_name = rand() % 60 +20;
rand_total_medallas = rand() % medallas;
medallas = medallas - rand_total_medallas;
rand_name = 0;
rand_sport = 0;
rand_medals = 0;
random = 0;
i = 0;
for (i=0; i < rand_total_name; i++)
rand_name = rand() % 200;
rand_sport = rand() % 10;
random = rand() % rand_sport;
rand_medals = rand_medals - random;
if (rand_medals<0)
random = random + rand_medals;
fill_struct (&all_year.segundo_ano, rand_total_name, rand_name, rand_sport, random, rand_total_medallas, i, names, sex, sports, medals);
r_name = rand() % 200;
strcpy(all_year.segundo_ano.encargado, names[r_name]);
rand_total_name = rand() % 60 +20;
rand_total_medallas = rand() % medallas;
medallas = medallas - rand_total_medallas;
// inicializaciones en 0
rand_name = 0;
rand_sport = 0;
rand_medals = 0;
random = 0;
i = 0;
for (i=0; i < rand_total_name; i++)
rand_name = rand() % 200;
rand_sport = rand() % 10;
random = rand() % rand_sport;
rand_medals = rand_medals - random;
if (rand_medals<0)
random = random + rand_medals;
fill_struct (&all_year.tercer_ano, rand_total_name, rand_name, rand_sport, random, rand_total_medallas, i, names, sex, sports, medals);
r_name = rand() % 200;
strcpy(all_year.tercer_ano.encargado, names[r_name]);
rand_total_name = rand() % 60 +20;
rand_total_medallas = rand() % medallas;
medallas = medallas - rand_total_medallas;
rand_name = 0;
rand_sport = 0;
rand_medals = 0;
random = 0;
i = 0;
for (i=0; i < rand_total_name; i++)
rand_name = rand() % 200;
rand_sport = rand() % 10;
random = rand() % rand_sport;
rand_medals = rand_medals - random;
if (rand_medals<0)
random = random + rand_medals;
fill_struct (&all_year.cuarto_ano, rand_total_name, rand_name, rand_sport, random, rand_total_medallas, i, names, sex, sports, medals);
//llenar encargado
r_name = rand() % 200;
strcpy(all_year.cuarto_ano.encargado, names[r_name]);
return all_year;
}
void fill_struct(struct juegos_interano *year, int rand_total_name, int rand_numb, int rand_sport, int rand_medals, int rand_total_medallas, int count, char names[200][20], char sex[200], char sports[10], int medals[40])
{
int i = 0;
int random = 0;
strcpy(year->participantes[count], names[rand_numb]);
year->sexo[count] = sex[rand_numb];
year->max_persona = rand_total_name;
for (i=0; i < rand_sport; i++){
random = rand() % 10;
year->deportes_partisipados[count][i] = sports[random];
}
for (i=0; i< rand_medals; i++){
do{
random = rand() % rand_total_medallas;
if (medals[random]==1){
if (medals[random]<10){
year->medallas[count][i] = 1;
medals[random] = 0;
}
else if (medals[random]>=10 && medals[random]<20){
year->medallas[count][i] = 2;
medals[random] = 0;
}
else if (medals[random]>=20 && medals[random]<30){
year->medallas[count][i] = 3;
medals[random] = 0;
}
else if (medals[random]>=30){
year->medallas[count][i] = 4;
medals[random] = 0;
}
}
}
while(medals[random]==0);
}
}
1条答案
按热度按时间zd287kbt1#
至少这个问题
缺少
{}
四个地方。示例: