Dereferencing pointer to incomplete type on a linked list

This is a discussion on Dereferencing pointer to incomplete type on a linked list within the C Programming forums, part of the General Programming Boards category; Hi, I'm pretty new at programming and I'm getting into linked lists. As part of a word database type thing ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    2

    Dereferencing pointer to incomplete type on a linked list

    Hi, I'm pretty new at programming and I'm getting into linked lists. As part of a word database type thing I'm writing a function searchWord that calls a function named searchNodeWord . searchNodeWord runs through a singly linked list and assigns the value of the correct node (based on a parameter called strKey) to a parameter called pResult. searchWord should then print one of the strings in the node stored in pResult.

    I't works fine until I try to printf the string in the pResult in [i]searchWord[\i]. I can use printf while I'm still in searchNodeWord just to see that I got the right node, but I can't seem to use it outside of the function. The compiler gives me a "Dereferencing pointer to incomplete type" error at that point.

    Here's the relevant code:

    Code:
    void searchNodeWord(sWordType *pFirst, string50 strKey, sWordType **pResult)
    {
         printf("\n");
         sWordType *pRun = NULL; //sWordType is the typedef i use for my nodes
         pRun = pFirst;
         char cChoice = '0';
         int nLoop = 1;
         
         do
         {
              if( pRun && strcmpi(pRun->strWord, strKey) == 0 )
              {
                  printf("Match Found: \n");
                  printf("Entry: %s\n", pRun->strWord);
                  printf("Translation: %s\n", pRun->strTrans);
                  
                  printf("\nIs this the correct entry? (Y/N)");
                  fflush(stdin);
                  scanf("%c", &cChoice);
                  
                  if( cChoice == 'N' || cChoice == 'n' )
                  {
                      pRun = pRun->pNext;
                  }
                  else if ( cChoice == 'Y' || cChoice == 'y' )
                       {
                            *pResult = pRun;
                            printf("-->%s\n", (*pResult)->strWord); //This works fine
                            nLoop = 0;
                            /*
                            printf("\n");
                            displayDetails(pRun);
                            */
                       }
                  //some other irrelevant code follows
    }
    Code:
    void searchWord(sWordType *pFirst) //pFirst points to the head of a singly linked list
    {
         string50 strKey;                         //typedef char string50[51]
         sWordType *pResult = NULL;     //sWordType is the typedef i use for my nodes
         
         printf("----|SEARCH WORD|----\n");
         printf("Current lexicon entires:\n");
         displayList(pFirst);                                 //Lists all available entries in linked list
         printf("\n");
         printf("Enter word to search: ");
         fflush(stdin);
         scanf("%s", &strKey);
         
         searchNodeWord(pFirst, strKey, &pResult);  //pResult should be updated to proper address
    
         //ERROR OCCURS AT NEXT LINE
         printf("-->%s\n", pResult->strWord);
         printf("\n");
    }
    Can anyone tell me why I cant seem to use that address fromm outside of searchNodeWord?
    Thanks in advance.
    Last edited by ehzzy; 03-22-2009 at 05:03 AM. Reason: personal stupidity

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I don't see a definition of pWord. Did you intend to use pResult instead?

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    2
    Oh, hahah. I changed pWord to pResult while i was posting to make things easier to read.
    They're all actually pWord on the actual code.

    Thanks for pointing that out. Lemme edit that.

    EDIT: Problem solved. I figured out how to return pointers from functions and did it that way instead. Thanks anyway.
    Last edited by ehzzy; 03-22-2009 at 05:50 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 02:17 PM
  2. error: dereferencing pointer to incomplete type
    By nasim751 in forum C Programming
    Replies: 2
    Last Post: 04-18-2008, 12:59 AM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  4. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  5. Replies: 6
    Last Post: 03-02-2005, 01:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21