请高人指点删除文件中指定数据
数据量不是很大但删时要删一个结构体数据
我编了个程序 想先把数据文件导入链表,找出要删的数据后,重新输入文件中。
编译时没报错
但运行时总是弹出程序停止的窗口
请高手帮我看看哪有错啊
程序代码:#include<stdio.h>
#include<stdlib.h>
struct teacher
{
int num;
char name[5];
char sex;
int wage;
struct teacher *next;
};
main()
{int n;
FILE *fq;
struct teacher *p,*q,*head;
fq=fopen("e:\\1.txt","rw");
if(fq==NULL)
{printf("can not open the file!\n");
exit(0);}
printf("Please input the one you want to delete\n");
scanf("%d",&n);
fread(head,sizeof(struct teacher),1,fq);
p=q=head;
while(!feof(fq)&&n!=p->num)
{fread(p,sizeof(struct teacher),1,fq);q=p;}
if(n==p->num) {q->next=p->next;}
else printf(" no such one");
p=q=head;
while(p->num!=NULL)
{fwrite(p,sizeof(struct teacher),1,fq);p=p->next;}
fclose(fq);
}








