ZhuYiTing22 2021-06-05 10:30 采纳率: 100%
浏览 20
已采纳

运行时显示指针空间未分配,但是找不到是哪里?

#include "iostream"
#include "string.h"
using namespace std;
struct staff
{
  char    num[6];      //职工工号
  char    name[20];    //职工姓名
  double  wage;  //职工工资
  struct staff *next;
};
struct staff *creat(int x)
{struct staff *head=NULL;
 struct staff *tail,*newnode;
cout<<"请分别输入职工工号、职工姓名、职工工资"<<endl;
 for(int i=0;i<x;i++)
 {newnode=new staff;
 cin.ignore();
 gets(newnode->num);
 gets(newnode->name);
 cin>>newnode->wage;
 if(head==NULL)
     head=newnode;
 else
     tail->next=newnode;
 tail=newnode;}
 tail->next=NULL ;
 return(head);}
void print(struct staff *head)
{struct staff *p=head;
while(p!=NULL)
{cout<<p->num<<" "<<p->name<<" "<<p->wage<<endl;
p=p->next;}
}
struct staff *chan(staff *head,int w,char n[])
{struct staff *p,*q;
p=head;
if(head==NULL)
    cout<<"空表";
else
{while(p!=NULL&&p->num!=n)
    {q=p;
   p=p->next;}
p->wage=w;}
   return(head);
}
int main()
{struct staff *head;
int x,w;
char n[6];
cout<<"请输入初始链表节点数x"<<endl;
cin>>x;
head=creat(x);
cout<<"请输入要修改的职工工号:"<<endl;
gets(n);
cout<<"请输入将工资改为:"<<endl;
cin>>w;
chan(head,w,n);
cout<<"修改后为:"<<endl;
print(head);
system("pause");
return 0;
}
希望有大神解答

 

  • 写回答

2条回答 默认 最新

  • 关注
    struct staff
    {
      char    num[6];      //职工工号
      char    name[20];    //职工姓名
      double  wage;  //职工工资
      struct staff *next;
    };
    改为
    typedef struct staff
    {
      char    num[6];      //职工工号
      char    name[20];    //职工姓名
      double  wage;  //职工工资
      struct staff *next;
    };
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line