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

#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;
}
希望有大神解答

 

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;
};

 

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632