#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
typedef struct book{
char name[16];
char id[8]; //存八位编号
int loaned; //借出
int num; //总数
double price;
char publisher[32];
char author[32];
struct book*next;
}book;
typedef struct student{
char id[8];
char name[16];
int overdue; //逾期数
char borrow_book_name[5][32]; //借书数,最大为5,用编号存
int borrow_book_num;
struct student*next;
}student;
void Print(book*Head);
int main(){
student sd = {"123456","hy",0,{"asd"},1,NULL};
FILE*fp = fopen("student.dat","w");
fwrite(&sd,sizeof(student),1,fp);
fclose(fp);
return 0;
}
都写进去了的。
注意一下空白字符也被写进去了,比如char name[16]这个,他就会占用16个字节,所以看起来会有很多空白
对于提出的问题,参考资料与代码并没有直接相关性,需要根据问题具体情况来回答。
首先需要确认结构体中各成员变量是否正确赋值,可以通过调试程序来确认。如果赋值正确,那么可能是在写入结构体的过程中出现了一些问题,比如指针未初始化、指针越界等等。需要逐步检查代码,确认出错的具体位置,然后进行修正。
如果无法确定错误原因,可以考虑重构代码,遵循良好的编程规范和风格,避免可能会导致错误的操作和写法。同时,在写代码的时候要注意细节和边界情况,保证代码的正确性和稳定性。