| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 578 人关注过本帖
标题:关于模拟操作系统总是报错说类型不匹配问题!求大神解决
只看楼主 加入收藏
back4663
Rank: 1
等 级:新手上路
帖 子:14
专家分:9
注 册:2012-7-3
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:7 
关于模拟操作系统总是报错说类型不匹配问题!求大神解决
#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&pound;&ordm;[             ]\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&pound;&ordm;[             ]\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&pound;&ordm;[             ]\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&pound;&ordm;[             ]\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);
 
搜索更多相关主题的帖子: next 操作系统 include 
2012-07-03 18:13
back4663
Rank: 1
等 级:新手上路
帖 子:14
专家分:9
注 册:2012-7-3
收藏
得分:0 
求大神帮忙啊
2012-07-03 21:31
随风飘荡
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:208
专家分:598
注 册:2011-9-9
收藏
得分:10 
main函数少了一个}
我不知道是不是你复制错,好歹也看看编译器的报错信息啊。

mfd:
struct linkf mfd;

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--;
   }
}
2012-07-04 01:46
back4663
Rank: 1
等 级:新手上路
帖 子:14
专家分:9
注 册:2012-7-3
收藏
得分:0 
回复 3楼 随风飘荡
mian 函数没错
  报错是这样的在自定义函数void popen()的第一个{上
  说的133 conflicting types for 'popen'
2012-07-04 17:29
jayjang
Rank: 1
等 级:新手上路
帖 子:3
专家分:1
注 册:2011-4-22
收藏
得分:0 
以下是引用back4663在2012-7-4 17:29:17的发言:

mian 函数没错
  报错是这样的在自定义函数void popen()的第一个{上
  说的133 conflicting types for 'popen'

你贴上来的代码是int popen()不是void popen()
2012-07-04 18:10
back4663
Rank: 1
等 级:新手上路
帖 子:14
专家分:9
注 册:2012-7-3
收藏
得分:0 
回复 5楼 jayjang
不好意思= =那是我自己调试的时候修改的= =但是报错的情况还是一样的
2012-07-04 21:31
随风飘荡
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:3
帖 子:208
专家分:598
注 册:2011-9-9
收藏
得分:0 
我是不知道你那份代码和发出来的有多大区别,你声明的mfd又不是数组变量怎么会出现mfd[j].username呢?
我只看到这一处,修改之后可通过编译,虽然用起来也.....
2012-07-05 00:30
back4663
Rank: 1
等 级:新手上路
帖 子:14
专家分:9
注 册:2012-7-3
收藏
得分:0 
回复 6楼 back4663
SOGA= =解决了= =·····
2012-07-05 10:32
快速回复:关于模拟操作系统总是报错说类型不匹配问题!求大神解决
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049183 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved