-sharpinclude <stdio.h>
-sharpinclude <stdlib.h>
-sharpinclude <math.h>
-sharpinclude <string.h>
//
typedef struct {
long id; //
char *name; //
int type; //
int hours; //
int teaching_hours; //
int experiment_or_machine_hours; //
float credit; //
int semester; //
} course;
//
void queryByCredit() {
float credit;
int flag, len = 0;
course *matching_courses = (course *) malloc(sizeof(course));
printf("%ld", sizeof(course));
FILE *fp = getFile("../course_info.txt", "r");
//
course course_temp;
course_temp.name = (char *) malloc(100 * sizeof(char));
while (1) {
printf(": ");
scanf("%f", &credit);
while (!feof(fp)) {
//
readCourseInfo(fp, &course_temp);
//
// , ,
if (fabsf(course_temp.credit - credit) < 0.01) {
// matching_courses[lenPP] = course_temp;
*(matching_courses + sizeof(course_temp) * lenPP) = course_temp;
matching_courses = (course *) realloc(matching_courses, sizeof(course));
}
}
//
showLine();
showCourseInfoHeader();
for (int i = 0; i < len; PPi) {
printCourseInfo(*(matching_courses + 40 * i));
}
showLine();
flag = isContinue();
if (flag == BACK)
break;
}
}
in my system (ubuntu 18.04)
Why does the address of matching_ courts [LenPP] increase only 28 at a time, when in fact it should add 40 to be correct