因此,当我尝试运行此错误时,出现了“结构之前的意外表达式”错误。它在代码块中显示的位置在race5k_calc的主函数中,我在该位置的上方留了一个粗体的注释,以便您轻松查看。有人可以告诉我这个错误是什么原因吗?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define TEAMS 200
#define RUNNERS 10000
#define LENGTH 20
#define TEAMSIZE 50
struct person {
char type[4];
char name[LENGTH];
int number;
int age;
int event;
float money;
float time;
};
struct team {
char name[LENGTH];
int numbers;
float money;
struct person *members;
};
struct person persons[1000];
struct team teams[200];
int per_size=0;
int t_size=0,i=0;
//Function prototypes
void registerPerson(struct person *p, char *name [LENGTH]);
void registerTeam(struct team *t, char * name[LENGTH]);
void race5k_calc(struct person *p, char *name [LENGTH]);
void race10k_calc(struct person *p, char * name [LENGTH]);
void race_marathon_calc(struct person *p, char * name [LENGTH]);
void donation_calc(struct person *p, struct person *members, char *name[LENGTH]);
//Main fucntion
int main() {
FILE *ifp;
char type[LENGTH];
char name [LENGTH];
int i;
struct person p,*members;
struct team t;
ifp = fopen("input.txt" , "r");
if(ifp == NULL) {
perror("Error opening file");
return -1;
}
while(feof(ifp)!=1){
if (strcmp(type,"INDV")==0) {
fread(&p, sizeof(p), 1, ifp);
registerPerson(&p,&name);
}
else if (strcmp(type,"TEAM")==0) {
fread(&t, sizeof(p), 1, ifp);
registerTeam(&t,&name);
members= (struct person *)malloc(t.numbers*sizeof(&p));
for(i=0;i<t.numbers;i++){
fread(&p, sizeof(p), 1, ifp);
members[i]=p;
registerPerson(&p,&name);
}
t.members=members;
}
}
//THE NEXT LINE IS WHERE THE ERROR SHOWS UP
race5k_calc(struct person *p, char *name [LENGTH]); //calling race 5k calcuation
race10k_calc(struct person *p, char * name [LENGTH]);//calling race 10k calculation
race_marathon_calc(struct person *p, char * name [LENGTH]);//calling marathon race
donation_calc(struct person *p, char * name [LENGTH]);//donation calculation.
break;
fclose(ifp);
return 0;
}
void registerPerson(struct person *p, char * name [LENGTH]) {
if(RUNNERS!=per_size) {
p->number=per_size;
(persons)[per_size]=*p;
per_size=per_size+1;
printf("%s registerd for the marathon race !",name[ ]);
}
else{
printf("no of members in the team is equal to 1");
}
return;
}
void registerTeam(struct team *t, char *name[LENGTH]){
if(t_size>=5 && t_size<=TEAMSIZE){
teams[t_size]=*t;
t_size=t_size+1;
// COMMENTS
printf(" %s registered for the team event ,they have been assigned the number %d ",name,t_size);
}
else{
printf("not registerd for team event ");
}
return;
}
void race5k_calc(struct person *p, char *name [LENGTH]) {
int i=0;
//calculate for individual persons
for(i=0;i<per_size;i++) {
//checking whether person event is 5k run and finding the winner
if(persons[i].event==5){
for(i=0;i<per_size;i++){
if(persons[i].time==persons[i+1].time){
p=&persons[i+1];
printf("5k race: %s has the fastest time with %s minutes", persons[i],persons[i].time);
}
else if(persons[i].time<persons[i+1].time){
p=&persons[i];
printf("5k race: %s has the fastest time with %s minutes", persons[i],persons[i].time);
}
else if(persons[i].time>persons[i+1].time){
p=&persons[i+1];
printf("5k race: %s has the fastest time with %s minutes", persons[i],persons[i].time);
}
}
}
}
return;
printf("person is not 5k race winner");
}
void race10k_calc(struct person *p, char * name [LENGTH]){
int i=0;
for(i=0;i<per_size;i++){
if(persons[i].event==10){
for(i=0;i<per_size;i++){
if(persons[i].time==persons[i+1].time) {
p=&persons[i+1];
printf("10k race: %s has the fastest time with %s minutes", persons[i],persons[i].time);
}
else if(persons[i].time<persons[i+1].time) {
p=&persons[i];
printf("10k race: %s has the fastest time with %s minutes", persons[i],persons[i].time);
}
else if(persons[i].time>persons[i+1].time) {
p=&persons[i+1];
printf("10k race: %s has the fastest time with %s minutes", persons[i],persons[i].time);
}
}
}
}
printf("person is not a 10k race winner");
return;
}
void race_marathon_calc(struct person *p, char * name [LENGTH]){
int i=0;
for(i=0;i<per_size;i++){
if(persons[i].event==42){
for(i=0;i<per_size;i++){
if(persons[i].time==persons[i+1].time) {
p=&persons[i+1];
//COMMENTS
}
else if(persons[i].time<persons[i+1].time) {
p=&persons[i];
printf("%s qualified in a marthon run with a time of %s" minutes !",persons[i].name,persons[i].time);
}
else if(persons[i].time>persons[i+1].time) {
p=&persons[i+1];
//COMMENTS
printf("%s qualified in a marthon run with a time of %s" minutes !",persons[i].name,persons[i].time);
}
}
}
}
printf("they have same run-time tie");
return;
}
void donation_calc(struct person *p, struct person *members, char *name[LENGTH]) {
float amt=0,t_amt=0,max_amt=0;
struct team t;
int i=0,j=0,l;
for(i=0;i<t_size;i++) {
t=teams[i];
members=t.members;
l=sizeof(members)/sizeof(*members);
for(j=0;j<l;j++) {
if(members[j].money>members[j].money) {
max_amt=members[j].money;
p=&members[j];
}
printf("\n%s -- %.2f",p->name,max_amt);
t_amt=t_amt+members[j].money;
printf("\nINDEX - %s ",t.name);
printf("%s raised the most money in %s with a donation of %s",person[i].name,t.name,t_amt);
}
}
amt=0;
for(i=0;i<per_size;i++){
amt+=persons[i].money;
printf("INDEX: %.2f\n\n", amt);
printf("the runners raised % 2f maount for charity",amt);
}
return;
}
最佳答案
调用函数时,无需指定参数类型。因此,将其称为race5k_calc(&p,&name);