回 帖 发 新 帖 刷新版面

主题:[讨论]求救啊~~~寻高手帮我解决一下这个程序出现的错误

#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<string.h>
#include<windows.h>
typedef struct node
{
 char time[20];
 char neirong[40];
 int bianhao;
 node *next;
}node;
typedef struct jilu
{
 char time[20];
 char neirong[40];
 int bianhao;
 jilu *next;

}jilu;
void chushihua(node *l)
{
 node *p,*q;
 p=l;
 char flag='y';
 while(flag=='y')
 {
  q=(node*)malloc(sizeof(node));
  printf("报警编号:\n");
  scanf("%d",&q->bianhao);
  fflush(stdin);
  printf("请输入报警时间:\n");
  gets(q->time);
  printf("请输入报警内容:\n");
  fflush(stdin);
  gets(q->neirong);
  p->next=q;
  p=q;
  printf("是否继续录入报警信息:\n");
  fflush(stdin);
  scanf("%c",&flag);
 }
 p->next=NULL;
}
void display(node *l)
{
 node *p;
 p=l->next;
 while(p!=NULL)
 {
  printf("报警编号:%d",p->bianhao);
  printf("报警信息:%s",p->neirong);
  printf("报警时间:%s\n",p->time);
  p=p->next;
 }
}
void chujing(node *l,jilu *k)
{
 node *p;
 jilu *q,*r;
 p=l->next;
 r=k;
 node *j;
 int i;
 int flag=1;
 printf("请输入你要出哪个警:\n");
 scanf("%d",&i);
 while(p!=NULL&&flag==1)
 {
  if(p->bianhao==i)
  {
  

   q=(jilu*)malloc(sizeof(jilu));
   q->bianhao=p->bianhao;
   strcpy(q->neirong,p->neirong);
   strcpy(q->time,p->time);
   r->next=q;
   r=q;
   r->next=NULL;
   flag=0;
   if(p=l->next)
    l->next=p->next;
   else
    j->next=p->next;
   free(p);
   
  }
  else
  {
   j=p;
   p=p->next;
  }
 }
 if(flag==1)
  printf("无该报警信息\n");
  
}
void charu(node *l)
{
 node *p,*q;
 p=l;
 int count=0;
 while(p->next!=NULL)
  p=p->next;

 char flag='y';
 while(flag=='y')
 {
  q=(node*)malloc(sizeof(node));
  printf("报警编号:\n");
  scanf("%d",&q->bianhao);
  fflush(stdin);
  printf("请输入报警时间:\n");
  gets(q->time);
  fflush(stdin);
  printf("请输入报警内容:\n");
  gets(q->neirong);

  p->next=q;
  p=q;
  printf("是否继续录入报警信息:\n");
  scanf("%c",&flag);
 }
 p->next=NULL;
 node *i;
 i=l;
 while(i->next!=NULL)
 {
   count++;
   i=i->next;
 }
 if(count>10)
 {
  printf("有很多警待出\n");
 }
 
}
void xianshichujing(jilu *k)
{
 jilu *p;
 p=k->next;
 if(p=NULL)
  printf("还未出警\n");
 while(p!=NULL)
 {
  printf("报警编号:%d",p->bianhao);
  printf("报警信息:%s",p->neirong);
  printf("报警时间:%s\n",p->time);
  p=p->next;
 }

}
void main()
{
 node *l;
 int i,j;
 jilu *k;
 l=(node *)malloc(sizeof(node));
 k=(jilu *)malloc(sizeof(jilu));
 l->next=NULL;
 k->next=NULL;
 for(i=0;i<6;i++)
 {
  Sleep(1000);
  printf("    sos   ");
 }
 printf("初始化报警信息:\n");
 chushihua(l);
 display(l);

 while(1)
 {
  printf("1:出警系统启动\n");
  printf("2:出警信息显示\n");
  printf("3:显示报警信息\n");
  printf("4:新的报警系统\n");
  printf("5:结束\n");
  fflush(stdin);
  scanf("%d",&j);
   switch(j)
   {
   case 1:
      chujing(l,k);
      break;
   case 2:
      xianshichujing(k);
      break;
   case 3:
      display(l);
      break;
   case 4:
      charu(l);
      break;
   case 5:
      exit(0);
      break;
   default:
      printf("error");
   }
 }



}



在win TC环境下编译不了,出现了很多错误,希望各位高手大侠能够给予指点,小生感激不尽!

回复列表 (共1个回复)

沙发

发错版了吧。
链表那里修改为struct node *next; 
struct jilu *next;

我来回复

您尚未登录,请登录后再回复。点此登录或注册