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条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改