struct student_link *load()
{
struct student_link *head,*p,*q;
FILE *fp;
fp=fopen("e:\\student8.dat","rb");
head=NULL;
q=(struct student_link *)malloc(sizeof(struct
student_link));/*给头结点申请空间*/
while(fread(q,sizeof(struct student_link)-4,1,fp)==1)
/*读取一位学生的信息放入结点q*/
{
q->next=NULL;
if(head==NULL)
{
head=q;
p=head;
}
else {
p->next=q;
p=p->next;
}
q=(struct student_link *)malloc(sizeof(struct student_link));
}
free(q);
fclose(fp);
return(head);
}
void main()
{
struct student_link *head;
long num;
int t;
scanf("%ld",&num);
head=load();
head=del1(head,num);
t=write(head);
/*write()运行成功返回int 0*/
printf("%d",t);
}
load()调用文件,以struct,载入链表中,函数如上第一段代码,在其他地方试过有问题
write()函数用来将删除了节点后的链表保存到文件中,这个函数我试过了没哟问题,调用的文件都没有问题,我估计是del1()函数有问题,运行时打印了write的返回值,并且调用的文件被写入了write()要写入的文件中,程序执行时好像直接跳过了del1(),del1()的代码如图?实在找不出原因?麻烦高人分析一下
谢谢 另,悬赏分是少不了的,答得好,我一定不吝惜分
|