-2

cで連結リストの要素へのポインタを取得したい。これが私のコードです。「型 'bigList' を返すときに互換性のない型ですが、'struct bigList **' が予期されていました」というエラーが表示されます。助けてください。ありがとう

     /*this is the struct*/
     struct bigList
     {
      char data;
      int count;
      struct bigList *next;
      };


      int main(void)
      {
        struct bigList *pointer = NULL;

        *getPointer(&pointer, 'A');  //here how do I store the result to a pointer 

       }

    /*function to return the pointer*/    
    bigList *getPointer(bigList *head, char value)
    {
      bigList temp;
      temp=*head;

      while(temp!=NULL)
       {
        if(temp->data==value)
        break;

        temp = temp->next;     
        }
    return *temp;      //here I get the error I mentioned
     }
4

1 に答える 1

1

ベースリストへのヘッドポインターと、ポインターを返したい場所の2つのポインターが必要です。

  int main(void)
  {
    struct bigList *pointer = NULL;

    struct bigList *retValPtr = getPointer(pointer, 'A');  //here how do I store the result to a pointer 

   }

   struct bigList *getPointer(struct bigList *head, char value)
   {
       struct bigList *temp;  // Don't really need this var as you could use "head" directly.
       temp = head;

       while(temp!=NULL)
       {
           if(temp->data==value)
             break;

           temp = temp->next;     
       }

       return temp;  // return the pointer to the correct element
   }

あなたのコードはこれについてちょっとランダムですが、それらがすべて同じタイプになるようにポインターの周りをどのように変更したかに注意してください。それはかなり重要です!

于 2013-02-28T21:39:21.933 に答える