struct myclass
{
    bool sexy;
    char name[10];
};
myclass *people[1000];
void insert(pos,myclass newnode)//pos 位置
{
      myclass *temp[1000];
      memcpy(people,temp,sizeof(people));
      temp[pos]=newnode;
      for(int i=pos+1;i<1000;i++)
      {
          temp[i]=people[i-1];
      }
}
void clearall()
{
    for(int i=0;i<1000;i++)
    {
        people[i]=0;
    }
}
//请问,为什么insert函数会出错?

解决方案 »

  1.   

    改成下面这样就行了struct myclass
    {
        bool sexy;
        char name[10];
    };
    myclass *people[1000];
    void insert(int pos,myclass *newnode)//pos 位置
    {
          myclass *temp[1000];
          memcpy(people,temp,sizeof(people));
          *temp[pos]=*newnode;
          for(int i=pos+1;i<1000;i++)
          {
              temp[i]=people[i-1];
          }
    }
    void clearall()
    {
        for(int i=0;i<1000;i++)
        {
            people[i]=0;
        }
    }
      

  2.   

    to shl6894() ( )人家不是说了吗,学习啊
      

  3.   

    通过调用函数要改变值指针对应的值,必须用*temp[pos]=*newnode;这样才是他们对应的值进行了变化,否则,你只改变了指针的值,而对应的值仍然没有改变
      

  4.   

    *temp[pos]=*newnode;
    Unhandled exception at 0x00424df4 in xy.exe: 0xC0000005: Access violation writing location 0x00000000.这句出错了,
      

  5.   

    temp[pos]=newnode;
    ==》
    temp[pos]=&newnode;
      

  6.   

    另外,
    memcpy(people,temp,sizeof(people));这个没有问题?
    它是 把 temp 复制到 people ...
    应该是 memcpy(temp,people,sizeof(people)); 这样吧?