我有一个代码,它将位于另一个双向链接列表内的双向链接列表中的学生编号(stdnum)保存到文件中。我注意到有时,它会打印“(null)”和额外的空格。我该如何避免这些?这是我的代码:
typedef struct frn{ //structure for friend
char stdnum[20];
struct frn *next;
struct frn *prev;
}friend;
typedef struct std{ //structure for student
char stdnum[20];
char name[20];
char course[10];
struct frn *friendh;
struct frn *friendt;
struct std *next;
struct std *prev;
}student;
FILE *fp1;
student *y = h->next;
friend *y1;
fp1 = fopen("friends.txt", "w");
if(y != t){
while(y != t){
y1 = y->friendh;
while(y1 != NULL){
fprintf(fp1, "%s\n", y1->prev->stdnum);
y1 = y1->next;
}
y = y->next;
}
}
fclose(fp1);