Void CreatLinkTa ()
{
Char n=0;
If ((fp=fopen (" information ", "rb"))==NULL)
{
Printf (" open file error ");
}
Do
{
P=(struct stu *) malloc (sizeof (struct stu));
If ((fread (p, sizeof (struct stu), 1, fp)!=1) & amp; & (feof (fp)))
{
Printf (" file read \ n ");
break;
}
n++;
If (n==1) head=p;
The else q - & gt; Next=p;
q=p;
} while (! The feof (fp));
P=the head;
fclose(fp);
Printf (" list have finished \ n ");
Q=p=head;
}
Delete data////
Void Cut_information ()
{
CreatLinkTa ();
char str[10];
Int n=0;
A struct stu *;
Q=p=head;
Printf (" \ n please enter the need to delete the student's name: ");
The scanf (" % s ", STR);
While (p!=NULL)
{
If (STRCMP (p - & gt; Name, STR)==0)
{
n++;
If (n==1)
{
A=p;
The head=q=p=a - & gt; Next;
Free (a);
}
The else
{
Q - & gt; Next=p - & gt; Next;
A=p;
P=p - & gt; Next;
Free (a);
}
}
q=p;
P=q - & gt; Next;
}
P=q=head;
Fp=fopen (" information ", "wb");
If (fp==NULL)
{
Printf (" open file error \ n ");
}
While (p!=NULL)
{
If (fwrite (p, sizeof (struct stu), 1, fp)!
=1){
Printf (" write error \ n ");
}
P=p - & gt; Next;
}
Printf (" corrected \ n ");
fclose(fp);
}
////modify data
Void Modify_information ()
{
CreatLinkTa ();
char str[10];
Int n=0;
A struct stu *;
Q=p=head;
Printf (" \ n please enter the student's name: ");
The scanf (" % s ", STR);
While (p!=NULL)
{n++;
If (STRCMP (p - & gt; Name, STR)==0)
{
A=(struct stu *) malloc (sizeof (struct stu));
Put1_information (a);
A - & gt; Next=NULL;
If (n==1) {head=q=a; A - & gt; Next=p - & gt; Next; P=a; }
The else {a - & gt; Next=p - & gt; Next; Q - & gt; Next=a; P=a; }
}
q=p;
P=p - & gt; Next;
}
P=q=head;
If ((fp=fopen (" information ", "wb"))==NULL)
{
Printf (" open file error \ n ");
return;
}
While (p!=NULL)
{
If (fwrite (p, sizeof (struct stu), 1, fp)!
=1){
Printf (" write error \ n ");
break;
}
P=p - & gt; Next;
}
Printf (" corrected \ n ");
fclose(fp);
}
CodePudding user response:
What went wrong?