// 創建鏈表 //
void CreatLinkTa()
{
char n=0;
if((fp=fopen("information","rb"))==NULL)
{
printf("打開檔案錯誤");
}
do
{
p=( struct stu*)malloc(sizeof(struct stu));
if((fread(p,sizeof(struct stu),1,fp)!=1)&&(feof(fp)))
{
printf("檔案讀入結束\n");
break;
}
n++;
if(n==1) head=p;
else q->next=p;
q=p;
}while(!feof(fp));
p=head;
fclose(fp);
printf("鏈表產生完畢\n");
q=p=head;
}
// 洗掉資料 //
void Cut_information()
{
CreatLinkTa();
char str[10];
int n=0;
struct stu *a;
q=p=head;
printf("\n請輸入需要洗掉學生的姓名:");
scanf("%s",str);
while(p!=NULL)
{
if(strcmp(p->name,str)==0)
{
n++;
if(n==1)
{
a=p;
head=q=p=a->next;
free(a);
}
else
{
q->next=p->next;
a=p;
p=p->next;
free(a);
}
}
q=p;
p=q->next;
}
p=q=head;
fp=fopen("information","wb");
if(fp==NULL)
{
printf("打開檔案錯誤\n");
}
while(p!=NULL)
{
if(fwrite(p,sizeof(struct stu),1,fp)!=1)
{
printf("寫入錯誤\n");
}
p=p->next;
}
printf("修改結束\n");
fclose(fp);
}
// 修改資料 //
void Modify_information()
{
CreatLinkTa();
char str[10];
int n=0;
struct stu *a;
q=p=head;
printf("\n請輸入學生姓名:");
scanf("%s",str);
while(p!=NULL)
{ n++;
if(strcmp(p->name,str)==0)
{
a=(struct stu*)malloc(sizeof(struct stu));
Put1_information(a);
a->next=NULL;
if(n==1){head=q=a;a->next=p->next;p=a;}
else {a->next=p->next;q->next=a;p=a;}
}
q=p;
p=p->next;
}
p=q=head;
if((fp=fopen("information","wb"))==NULL)
{
printf("打開檔案錯誤\n");
return;
}
while(p!=NULL)
{
if(fwrite(p,sizeof(struct stu),1,fp)!=1)
{
printf("寫入錯誤\n");
break;
}
p=p->next;
}
printf("修改結束\n");
fclose(fp);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/243417.html
標籤:新手樂園
上一篇:Linux下依賴于第三方庫生成自己的動態庫,然后g++編譯呼叫生成的動態庫的時候報:對'boost::re_detail......'未定義的參考
