这项工作,但是我必须使用指针算法。
struct lsn
{
char lsn_nm[50];
};
struct Student
{
char name[20];
char surname[20];
char st_id[11];
struct lsn* ls;
};
int main()
{
int stdnt, drs;
int i,j;
printf("Number of students: ");
scanf("%d", &stdnt);
struct Student* arr = malloc(stdnt*sizeof(struct Student));
for (i = 0; i < stdnt; i++)
{
printf("Number of lessons: ");
scanf("%d", &drs);
(arr+i)->ls = malloc(drs*sizeof(struct lsn));
for (j=0;j<drs;j++)
{
printf("Name of Lesson: ");
scanf("%s", (arr+i)->ls[j].lsn_nm);
}
}
return 0;
}
如果我尝试这样:(arr + i)->(ls + j).lsn_nm,则会收到错误消息“'('令牌之前的预期标识符” 请帮助我。