1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Problem with a function that returns a pointer

Discussion in 'C' started by flyboy1506, Jul 28, 2008.

  1. flyboy1506

    flyboy1506 Banned

    Joined:
    Jul 28, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Working on a programming assignment and am stuck on one function.
    Code:
    BOOK_STRUCT* get_book_by_title (BOOK_STRUCT library[], char* title, int lib_size)
    {
     BOOK_STRUCT * Result;
     for (int x=0;x<=lib_size;x++){
         if (title == library[x].title)
         break;
         if (x==lib_size)
          Result = NULL;
         else
         //Result = (*library[x]);
       
       //Result = NULL;
         return Result;   
    }   
    } 
    This function receives a string from the user (title) and is supposed to go through a predefined array (the library) and compare it against the title member. If it finds it, it returns a pointer to that object, if not, it returns a null pointer.

    This actually compiles but unfortunately does not work in the overall program.

    I'm thinking my problem is with the if (title == library[x].title) line but since I am new to c++ I will defer to you guys.

    Any assistance you might offer would be appreciated.

    Thanx
     
    Last edited by a moderator: Jul 29, 2008
  2. flyboy1506

    flyboy1506 Banned

    Joined:
    Jul 28, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Figured it out. Thanx
     

Share This Page