好的,所以我遇到了一个奇怪的问题,但仍然无法解决,我开始发疯了。我试图从结构中调用变量,但它给了我随机值。我目前使用
调用我的结构printf("%s %i %i %i %i\n", student[0].lastName, student[0].assignmentScore, student[0].quizScore[0], student[0].quizScore[1], student[0].finalExamScore);
printf("%s %i %i %i %i\n", student[1].lastName, student[1].assignmentScore, student[1].quizScore[0], student[1].quizScore[1], student[1].finalExamScore);
printf("%s %i %i %i %i\n", student[2].lastName, student[2].assignmentScore, student[2].quizScore[0], student[2].quizScore[1], student[2].finalExamScore);
但是我回来了
我正在寻找的输出是
但是如果我从
更改结构声明struct student student[100];
到
struct student student[3];
我又获得了这些随机值,我正在寻找的输出是
我也只使用2个学生,所以3个就足够了。我不是在声明数组结构吗?
这就是我分配结构的方式
token = strtok(buffer, search);
N = atoi(token);
int dividerCount = 1;
int quizCounter = 0;
printf("'%s'\n", token);
while(token){
if(count == 0){
token = strtok(NULL,search);
M = atoi(token);
printf("'%s'\n", token);
}
if(count >= 1){
for(j = 0; j < (N * (3 + M)); j++){
int divider = M + 3;
if (dividerCount == 1){
token = strtok(NULL, search);
strcpy(student[count - 1].lastName, token);
printf("'%s'\n", token);
} else if(dividerCount == 2){
token = strtok(NULL, search);
student[count - 1].assignmentScore = atoi(token);
printf("'%s'\n", token);
} else if(M + 3){
token = strtok(NULL, search);
student[count - 1].finalExamScore = atoi(token);
printf("'%s'\n", token);
} else {
token = strtok(NULL, search);
printf("'%i'\n", atoi(token));
student[count - 1].quizScore[quizCounter] = token;
quizCounter++;
}
dividerCount++;
}
if(token)
break;
}
count++;
}