我在我的一个函数中创建了结构数组,我想在另一个文件中使用该结构数组。我的结构是这样的:
struct competitors{
int competitorNumber;
char registeredCourse;
char name[50];
};
编辑:对不起,我复制了错误的结构!!!
这就是我填充结构的方式:
lines = lineCount(fileName);
struct checkPoints checkPoint[lines];
sizeOfCheckPoints = lines;
chPo = fopen(fileName, mode);
if (chPo == NULL) {
printf("Can't find the files.");
exit(1);
} else {
for (i = 0; i < lines; i++) {
fscanf(chPo, "%c %d %d %d:%d\n", &checkPoint[i].dropOut, &checkPoint[i].currentPoint, &checkPoint[i].competitor, &checkPoint[i].hour, &checkPoint[i].minute);
}
}
它完美地填充结构,但我不知道我应该如何在另一个文件中使用它。这就是我尝试使用它的方式,但它似乎不起作用:
for(i = 0; i<sizeOfCompetitors; i++){
if (name == competitor[i].name){
printf("Here is comp details: %d\t%c\t%s", competitor[i].competitorNumber, competitor[i].registeredCourse, competitor[i].name);
}else{
printf("%s was not found", name);
}
}
有人可以帮我吗?