Thread: list searching program

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    10

    list searching program

    What is wrong with the following search program for finding the node on List L, containing the airport code A and returning a pointer to it?

    Code:
    NodeType *FindNode(char *A, NodeType *L)
    {
         while ((strcmp(L->Airport,A)!=0) && (L!=NULL))
         {
                L=L->Link;
         }
    
         return L;
    }
    I have been at this for a while and can't figure out the problem. It seems fine to me. If the Airport codes do not match and the next node is not NULL, it advances to the next node within the while loop, until it finds a match. If the list is empty, or if there are no matches it will exit the loop and return NULL. Any hints as to what is wrong with this code would be appreciated.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I think you want to check if L is NULL before you try to access L->Airport to compare it with A.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  3. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  4. simple list and driver program help
    By rugger78 in forum C++ Programming
    Replies: 4
    Last Post: 10-24-2006, 03:37 AM
  5. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 06:40 PM