关于模拟操作系统总是报错说类型不匹配问题!求大神解决
#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;
struct links *ufd,*p2,*q2;
struct linkr *p,*q;
struct linkt *afd,*p3,*q3;
char X[16],s,username[16],name[16],ri,chg;
int r,i,w,k,n,m,j,t,flag,id,mi;
void print1()
{
int i;
printf("\n MFD:\n");
printf("----------------\n");
for(i=0;i<n;i++)
{
printf("| %s",mfd.username);
printf("\n----------------\n");
}
}
void print2()
{
int i;
for(i=0;i<n;i++)
if (flag==i && ufd!=NULL)
{
printf("\nMFD__[%s]\n",mfd.username);
p2=mfd.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()
{
int i;
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)
{
if (p->sex)
printf("|%5d |%10s | 'man' |\n",i,p->name);
else
printf("|%5d |%10s | 'woman' |\n",i,p->name);
i++; p=p->next;
printf("---------------------------------------\n");
}
}
}
else printf("The file hasn't opened!\n");
}
void pcreate()
{
printf("Input create filename:");scanf("%s",X);
q2=ufd;
if (q2!=NULL)
{
while((strcmp(q2->filename,X)!=0)&&(q2->next!=NULL))
q2=q2->next;
if(strcmp(q2->filename,X)==0)
{
printf("File has already been created!\n");
return;
}
}
p2=(struct links *)malloc(sizeof(struct links));
if(ufd==NULL) ufd=p2; else q2->next=p2;
strcpy(p2->filename,X);
p2->length=0;
p2->next=NULL;
p2->headlink=NULL;
printf("\"%s\" Create File is Finished!\n",X);
}
int popen()
{
p2=ufd;
printf("Input Open filename:");
scanf("%s",X);
if(p2!=NULL)
{
while((strcmp(p2->filename,X)!=0)&&(p2->next!=NULL))
p2=p2->next;
if(strcmp(p2->filename,X)==0)
{
q3=afd;
if(afd!=NULL)
{
while((strcmp(q3->filename,X)!=0)&&(q3->next!=NULL))
q3=q3->next;
if(strcmp(q3->filename,X)==0)
{
printf("The file \"%s\" has been opened.\n",X);
return;
}
}
p3=(struct linkt *)malloc(sizeof(struct linkt));
if(afd==NULL) afd=p3; else q3->next=p3;
strcpy(p3->filename,X);
p3->length=p2->length;
p3->headlink=p2->headlink;
p3->flag=0;
p3->next=NULL;
printf("The file \"%s\" is opened.\n",X);
return;
}
}
printf("Can't find \"%s\" file in \"%s\" USER.\n",X,username);
}
void pclose()
{
if (afd)
{
p3=afd;
while(strcmp(p3->filename,X)!=0&&p3->next!=NULL) {q3=p3;p3=p3->next;}
if (strcmp(p3->filename,X)==0)
{
if (strcmp(afd->filename,X)==0){afd=afd->next;q3=afd;}
else q3->next=p3->next;
if (p3->flag)
{
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);
printf("The file \"%s\" is Closed.\n",X);
return;
}
}
printf("The file \"%s\" isn't opened!\n",X);
return;
}
void pdelete()
{
if (afd)
{
q3=afd;
while (strcmp(q3->filename,X)!=0&&q3->next) q3=q3->next;
if (strcmp(q3->filename,X)==0) pclose();
}
if(ufd)
{
p2=ufd;
while(strcmp(p2->filename,X)!=0&&p2->next!=NULL) {q2=p2;p2=p2->next;}
if (strcmp(p2->filename,X)==0)
{
if (strcmp(ufd->filename,X)==0){ufd=ufd->next;q2=ufd;}
else q2->next=p2->next;
if (p2->headlink)
{
q=p=p2->headlink;
while (p){p=q->next;free (q);p2->length--;q=p;}
}
free (p2);
printf("The file \"%s\" is Deleted.\n",X);
return;
}
}
printf("The files \"%s\" is not found!\n",X);
return;
}
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()
{
q3=afd;
if (q3)
{
while(strcmp(q3->filename,X)!=0&&q3->next!=NULL)
q3=q3->next;
if (strcmp(q3->filename,X)==0)
{
q=q3->headlink;
if(!q) {printf("The file \"%s\" is NULL!\n",X);return;}
id=1;
do
{
printf("Please Input Record-number:[ ]\b\b\b");
getchar();
scanf("%c",&ri);
if (ri-48>q3->length||ri-48<id)
printf("Record-number is Wrong!\n");
}while(ri-48>q3->length||ri-48<id);
while(id<ri-48)
{q=q->next;id++;}
printf("| ID | name | sex |\n");
printf("---------------------------------------\n");
if (q->sex)
printf("|%5d |%10s | 'man' |\n",id,q->name);
else
printf("|%5d |%10s | 'woman' |\n",id,q->name);
printf("---------------------------------------\n");
do
{
printf("Do you want to change this file: (Y/N)[ ]\b\b");
getchar();
scanf("%c",&chg);
}while(chg!=121&&chg!=89&&chg!=110&&chg!=78);
if (chg==121||chg==89)
{
printf("Please Input username:[ ]\b\b\b\b\b\b\b\b\b\b\b\b\b");scanf("%s",name);
strcpy(q->name,name);
printf("Please Input usersex:(0 or 1)[ ]\b\b");scanf("%d",&mi);
q->sex=mi;
}
return;
}
}
printf("The files \"%s\" isn't Opened!\n",X);
return;
}
void pwrite()
{
q3=afd;
if (afd)
{
while(strcmp(q3->filename,X)!=0&&q3->next!=NULL)
q3=q3->next;
if (strcmp(q3->filename,X)==0)
{
p=(struct linkr *)malloc(sizeof(struct linkr));
printf("Please Input Username:[ ]\b\b\b\b\b\b\b\b\b\b\b\b\b");
scanf("%s",name);
strcpy(p->name,name);
printf("Please Input Usersex (0 or 1):[ ]\b\b");
scanf("%d",&mi);
if (mi==1)
mi=1;
else
mi=0;
p->sex=mi;
p->next=NULL;
if (!q3->headlink) {q3->headlink=p;}
else
{ q=q3->headlink;
while(q->next)
q=q->next;
q->next=p;
}
q3->flag=1;
q3->length++;
return;
}
}
printf("The file \"%s\" isn't Opened.\n",X);
return;
}
void main()
{
afd=NULL; ufd=NULL;
for (i=0;i<5;i++)
{
strcpy(mfd.username," ");
mfd.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.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.username,username)!=0));i++);
if(i>=n)
{
printf("Not found Username!\n");
}
} while(i>=n);
t=0; flag=i; ufd=mfd.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':printf("Please Input Delete filename£º[ ]\b\b\b\b\b\b\b\b\b\b\b\b\b");scanf("%s",X);pdelete();break;
case '4':printf("Please Input Close filename£º[ ]\b\b\b\b\b\b\b\b\b\b\b\b\b");scanf("%s",X);pclose();break;
case '5':printf("Please Input Read filename£º[ ]\b\b\b\b\b\b\b\b\b\b\b\b\b");scanf("%s",X);pread();break;
case '6':printf("Please Input Write filename£º[ ]\b\b\b\b\b\b\b\b\b\b\b\b\b");scanf("%s",X);pwrite();break;
case '7':print2();break;
case '8':print3();break;
case '9':t=1;close();
}
mfd.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);