📄 zzq.txt
字号:
#include <stdio.h>
#include<string.h>
#include<malloc.h>
struct linkf
{char username[16];
struct links *next;
};
struct linkr
{char name[16];
int sex;
struct linkr *next;
};
struct links
{char filename[16];
struct linkr *headlink;
int length;
struct links *next;
};
struct linkt
{char filename[16];
int flag;
int length;
struct linkr *headlink;
struct linkt *next;
};
struct linkf mfd[5];
struct links *ufd,*p2,*q2;
struct linkr *p,*q;
struct linkt *afd,*p3,*q3;
char X[16],s,username[16];
int r,i,w,k,n,m,j,t,flag;
void print1()
{
int i;
printf("\n MFD:\n");
printf("----------------\n");
for(i=0;i<n;i++)
{
printf("| %s",mfd[i].username);
printf("\n----------------\n");
}
}
void print2()
{
int i;
for(i=0;i<n;i++)
if (flag==i && ufd!=NULL)
{
printf("\n MFD__[%s]\n",mfd[i].username);
p2=mfd[i].next;
printf("+_UFD-Filename_+_ Length _+\n");
while(p2!=NULL)
{
printf("|%10s | %4d |\n",p2->filename,p2->length);
p2=p2->next;
printf("+--------------+--------------+\n");
}
}
if(ufd==NULL) printf("\nUFD_[%s] is NULL\n",username);
if(afd!=NULL)
{
p3=afd;
printf("\n\nAFD_[%s]\n",username);
printf("+-----Filename-----+----length---+\n");
while(p3!=NULL)
{
printf("|%12s | %d |\n",
p3->filename,p3->length);
p3=p3->next;
printf("+------------------|-------------+\n");
}
}
else
printf("\n\nAFD_[%s] is NULL\n",username);
}
void print3()
{
p3=afd;
printf("Input printing-filename:"); scanf("%s",X);
if(p3!=NULL)
{
while((strcmp(p3->filename,X)!=0)&&(p3->next!=NULL))
p3=p3->next;
if(strcmp(p3->filename,X)!=0)
printf("The file hasn't opened!\n");
else
if(p3->headlink==NULL)
printf("The file is NULL!\n");
else
{
p=p3->headlink; i=1;
printf("| num | name | sex |\n");
printf("---------------------------------------\n");
while (p!=NULL)
{
printf("|%5d |%10s | %d |\n",i,p->name,p->sex);
i++; p=p->next;
printf("---------------------------------------\n");
}
}
}
else
printf("The file hasn't opened!\n");
}
void pcreate()
{ struct links *temp=0,*pre=0;
temp=ufd;
printf("Input create filename :");
scanf("%s",X);
while(temp!=NULL && strcmp(temp->filename,X)!=0)
{
pre=temp;
temp=temp->next;
}
if(temp==NULL)
{ p2=(struct links *)malloc(sizeof(struct links));
temp=p2;
if(NULL==ufd)
ufd=temp;
else
pre->next=p2;
strcpy(temp->filename,X);
temp->next=NULL;
temp->length=0;
temp->headlink=NULL;
printf("Success!");
}
else
printf("\nThe filename has already been Created!\n");
}
void popen()
{ struct links *temp=0,*pre=0;
struct linkt *tempt=0,*pret=0;
printf("Input open filename:");
scanf("%s",X);
temp=ufd;
while(temp!=NULL)
{
pre=temp;
if(0==strcmp(pre->filename,X))
break;
else
temp=temp->next;
}
if(NULL==temp)
printf("\ncan't find\"%s\" file in \"%s\"USER.",X,mfd[i].username);
else
{
tempt=afd;
while(tempt!=NULL && strcmp(tempt->filename,X)!=0)
{
pret=tempt;
tempt=tempt->next;
}
if(tempt==NULL)
{
p3=(struct linkt *)malloc(sizeof(struct linkt));
tempt=p3;
if(NULL==afd)
afd=tempt;
else
pret->next=tempt;
strcpy(tempt->filename,X);
tempt->next=NULL;
tempt->length=0;
tempt->flag=0;
tempt->headlink=NULL;
printf("Success!");
}
else
printf("\nThe file \"%s\"has been opened",X);
}
}
void pclose()
{
struct links *temp=0,*pre=0;
struct linkt *tempt=0,*pret=0;
printf("\nInput filename you want to close:");
scanf("%s",X);
tempt=afd;
while(tempt!=NULL && strcmp(tempt->filename,X)!=0)
{
pret=tempt;
tempt=tempt->next;
}
if(tempt==NULL)
printf("\nThe file has not been open");
else
{
if(NULL==pret)
afd=tempt->next;
else
pret->next=tempt->next;
if(tempt->flag)
{
temp=ufd;
while(temp!=NULL)
{
pre=temp;
if(0==strcmp(pre->filename,X))
break;
else
temp=temp->next;
}
if(NULL==temp)
printf("The file \"%s\" can not be found in ufd",X);
else
{
temp->length=tempt->length;
temp->headlink=tempt->headlink;
}
free(tempt);
}
printf("success!");
}
}
void pdelete()
{
struct links *temp=0,*pre=0;
struct linkt *tempt=0,*pret=0;
printf("\nInput filename to be deleted :");
scanf("%s",X);
tempt=afd;
while(tempt!=NULL && strcmp(tempt->filename,X)!=0)
{
pret=tempt;
tempt=tempt->next;
}
if(tempt!=NULL)
{
if(NULL==pret)
afd=tempt->next;
else
pret->next=tempt->next;
free(tempt);
}
temp=ufd;
while(temp!=NULL)
{
if(0==strcmp(temp->filename,X))
break;
else
{
pre=temp;
temp=temp->next;
}
}
if(NULL==temp)
printf("\nThe file \"%s\" can not be found in user \"%s\"",X,mfd[i].username);
else
{
if(0==pre)
ufd=temp->next;
else
pre->next=temp->next;
free(temp);
}
}
void close()
{
while (afd!=NULL)
{
p3=afd; afd=afd->next;
p2=ufd;
while(strcmp(p2->filename,p3->filename)!=0
&&p2->next!=NULL) p2=p2->next;
if(strcmp(p2->filename,p3->filename)==0)
{
p2->length=p3->length; p2->headlink=p3->headlink;
}
free(p3);
}
}
void pread()
{
struct linkt *tempt=0,*pret=0;
struct linkr *tempr=0,*prer=0;
int No,j;
printf("\nInput filename you want to open:");
scanf("%s",X);
tempt=afd;
while(tempt!=NULL && strcmp(tempt->filename,X)!=0)
{
pret=tempt;
tempt=tempt->next;
}
if(tempt==NULL)
printf("\nThe file has not been open");
else
{
printf("\nInput the NO of record that you want to read:");
scanf("%d",&No);
tempr=tempt->headlink;
for(j=0;j<No;j++)
if(NULL==tempr)
{
printf("\nIt can not find that the NO%d record",No);
prer=tempr;
break;
}
else
{
prer=tempr;
tempr=tempr->next;
}
if(prer!=NULL)
printf("\n%d\t%s\t%d",No,prer->name,prer->sex);
}
}
void pwrite()
{
struct linkt *tempt=0,*pret=0;
struct linkr *tempr=0,*prer=0;
int j;
printf("\nInput filename you want to open:");
scanf("%s",X);
tempt=afd;
while(tempt!=NULL && strcmp(tempt->filename,X)!=0)
{
pret=tempt;
tempt=tempt->next;
}
if(tempt==NULL)
printf("\nThe file has not been open");
else
{
p=(struct linkr *)malloc(sizeof(struct linkr));
printf("\nInput student-name :");
scanf("%s",X);
printf("\nInput student-sex 1(male) or 0(female):");
scanf("%d",&j);
strcpy(p->name,X);
p->sex=j;
p->next=NULL;
tempr=tempt->headlink;
if(NULL==tempt->headlink)
tempt->headlink=p;
else
{
while(tempr!=NULL)
{
prer=tempr;
tempr=tempr->next;
}
prer->next=p;
}
tempt->flag=1;
tempt->length++;
printf("Success!");
}
}
void main()
{
afd=NULL; ufd=NULL;
for (i=0;i<5;i++)
{
strcpy(mfd[i].username," ");
mfd[i].next=NULL;
}
printf("User number N(N<=5)=");scanf("%d",&n);
for(i=0;i<n;i++)
{
w=0;
printf("User MFD username X[%d]=",i+1);scanf("%s",X);
for (j=0;j<n;j++)
if(strcmp(mfd[j].username,X)==0)
w=1;
if(w==0)
strcpy(mfd[i].username,X);
else
{
printf("\nThe Username has been Created!\n");i--;}
}
do
{
print1();
do
{
printf("Input user name you want to operate:");
scanf("%s",username);
for(i=0;(i<n&&(strcmp(mfd[i].username,username)!=0));i++);
if(i>=n)
{printf("Not found Username!\n");}
}while(i>=n);
t=0;
flag=i;
ufd=mfd[i].next;
do
{
printf("\n------------------------------------\n");
printf(" 1--Creat 2--Open 3--Delete\n");
printf(" 4--cLose 5--Read 6--Write\n");
printf(" 7--disPlay 8--fileplay 9--Quit\n");
printf("------------------------------------\n");
printf(" Select[ ]\b\b");
scanf("%s",&s);
switch(s)
{
case '1':pcreate();break;
case '2':popen();break;
case '3':pdelete();break;
case '4':pclose();break;
case '5':pread();break;
case '6':pwrite();break;
case '7':print2();break;
case '8':print3();break;
case '9':t=1;close();
}
mfd[i].next=ufd;
}while(!t);
printf("\n---------------------------------------\n");
printf("| 1--Edit other user , 2--Quit |\n" );
printf("---------------------------------------\n");
printf(" Select[ ]\b\b");
scanf("%d",&m);
if(m==2)
r=1;
else
r=0;
}while(!r);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -