Linked List

This is a discussion on Linked List within the C Programming forums, part of the General Programming Boards category; Ok...I'm trying to grab (scanf) an itemName and a value (price) from the user - this program compiles, but when ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    24

    Linked List

    Ok...I'm trying to grab (scanf) an itemName and a value (price) from the user - this program compiles, but when i try to run the program, it says :

    1) linkList error LNK2019: unresolved external symbol "struct node * __cdecl search(struct node *,float)" (?search@@YAPAUnode@@PAU1@M@Z) referenced in function _main


    2) linkList error LNK2019: unresolved external symbol "int __cdecl deletenode(struct node *,char * const)" (?deletenode@@YAHPAUnode@@QAD@Z) referenced in function _main

    3) linkList error LNK2019: unresolved external symbol "int __cdecl insertnode(struct node *,char * const)" (?insertnode@@YAHPAUnode@@QAD@Z) referenced in function _main

    Can anyone help? Here's my code:

    Code:
    //Declarations for Linked List 
    
    #include <stdio.h> 
    #include <stdlib.h> 
    #include <string.h> 
    
    #define DUMMY_TRAILER 100   /*Assume all valid numbers fall between 1 and 99*/ 
    #define DUPLICATE 1 
    #define NEW_NODE 0 
    #define FOUND 1 
    #define NOT_FOUND 0 
    
    typedef struct node NODE; 
    struct node 
    { 
       char itemName[10]; 
       float value; 
       NODE* next; 
    }; 
    
    /* Function prototypes */ 
    NODE* init_list(void); 
    int insertnode(NODE*, char []); 
    int deletenode(NODE*, char []); 
    NODE* search(NODE*, float value); 
    void traverse(NODE*); 
    
    
    /* Driver to test the functions */ 
    int main() 
    { 
       NODE* list, *nodeptr; 
       char itemName[10]; 
       float value; 
       int found, duplicate, number=0; 
    
       list = init_list(); 
       while(printf("Enter an item and it's price, or -1 to quit: "), scanf("%d", "%c", &value, &itemName), 
          number != -1) 
       { 
          duplicate = insertnode(list, itemName); 
          if (duplicate) 
          { 
             printf("That item is already in the list.\n"); 
          }   /*end of if*/ 
    
       }   /*end of while*/ 
    
       traverse(list);   /*Print out the values in the list*/ 
    
          while(printf("Enter an item and it's price, or -1 to quit: "), scanf("%d", "%c", &value, &itemName), 
          number != -1) 
       { 
          found = deletenode(list, itemName); 
          if (!found) 
          { 
             printf("Could not find the item with value of: %c\n", itemName); 
          }   /*end of if*/ 
          else 
          { 
             printf("Deleted %c\n", itemName); 
          }   /*end of else*/ 
    
       }   /*end of while*/ 
    
       traverse(list); 
    
         while(printf("Enter an item and it's price, or -1 to quit: "), scanf("%d", "%c", &value, &itemName), 
          number != -1) 
       { 
          nodeptr = search(list, value); 
          if (!nodeptr) 
          { 
    
             printf("Could not find node with value of: %c\n", itemName); 
          }   /*end of if*/ 
          else 
          { 
             printf("Node with value of %d was found!\n", nodeptr->value); 
          }   /*end of else*/ 
    
       }   /*end of while*/ 
    
       return 0; 
    
    }   /*end of main*/ 
    
    
    /* Initilization of an empty ordered linked list */ 
    NODE* init_list(void) 
    { 
       NODE* list; 
    
       if ( (list = (NODE*)malloc(sizeof(NODE)) ) == NULL) 
       { 
          printf("Fatal malloc error in main\n"); 
          exit(1); 
       }   /*end of if*/ 
    
       list->value = 0; 
    
       if ((list->next = (NODE*)malloc(sizeof(NODE))) == NULL) 
       { 
          printf("Fatal malloc error in main\n"); 
          exit(2); 
       }   /*end of if*/ 
    
       list->next->value = DUMMY_TRAILER; 
       list->next->next = NULL; 
       return list; 
    }   /*end of init_list*/ 
    
    /* Insert nodes into ordered linked list */ 
    int insertnode(NODE* list, float value, char itemName[]) 
    { 
       NODE* current = list->next; 
       NODE* previous = list; 
       NODE* newptr; 
    
       while(value > current->value) 
       { 
          previous = current; 
          current = current->next; 
       }   /*end of while*/ 
    
       if (value == current->value) 
       { 
          return DUPLICATE; 
       }   /*end of if*/ 
       else 
       { 
          if ( (newptr = (NODE*)malloc(sizeof(NODE))) == NULL) 
          { 
             printf("Fatal malloc error in insert!\n"); 
             exit(3); 
          }   /*end of if*/ 
          /*Fill up new node and link it in*/ 
          newptr->value = value;
       strcpy(newptr->itemName, itemName);
          newptr->next = current; 
          previous->next = newptr; 
          return NEW_NODE; 
       }   /*end of else*/ 
    
    }   /*end of insert*/ 
    
    /*Delete a node from ordered linked list*/ 
    int deletenode(NODE* list, int value) 
    { 
       NODE* current = list->next; 
       NODE* previous = list; 
    
       while(value > current->value) 
       { 
          previous = current; 
          current = current->next; 
       }   /*end of while*/ 
    
       if (value != current->value) 
       { 
          return NOT_FOUND; 
       }   /*end of if*/ 
       else 
       { 
          previous->next = current->next; 
          free(current); 
          return FOUND; 
       }   /*end of else*/ 
    
    }   /*end of delete*/ 
    
    /*Find a node in an ordered linked list*/ 
    NODE* search(NODE* list, int value) 
    { 
       list = list->next;   /*skip dummy header*/ 
    
       while (value >= list->value) 
       { 
          if (value == list->value) 
          { 
             return list; 
          }   /*end of if*/ 
          list = list->next; 
       }   /*end of while*/ 
    
       return NULL; 
    }   /*end of search*/ 
    
    /*Traverse the nodes in an ordered linked list*/ 
    void traverse(NODE* list) 
    { 
       list = list->next;   /*Skip over dummy node*/ 
    
       while(list->value != DUMMY_TRAILER) 
       { 
          printf("%d\n", list->value); 
          list = list->next; 
       }   /*end of while*/ 
    
    }   /*end of traverse*/

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Check the arguments that you have in your function prototypes, and then see if they match the arguments where you actually have the function code. You'll notice some discrepancies.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    24
    OK...my function prototypes are now:

    Code:
    /* Function prototypes */ 
    NODE* init_list(void); 
    int insertnode(NODE*, float value, char itemName[]); 
    int deletenode(NODE*, float value, char itemName[]); 
    NODE* search(NODE*, float value, char itemName[]); 
    void traverse(NODE*);
    Made sure everything corresponds....still the same errors?

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    You also forgot to look at what you're passing to the functions when you're calling them.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    Your prototypes have changed, have you also changed the functions themselves and what they take. If so, then you are making function calls and not passing the correct amount of parameters. check out line 9, in the main() function. It only passes 2 parameters, the functions needs 3. Fix these and see what, if any errors you get.

    Hint: You may need to write down your prototypes, your functions location and the parameters it takes, and each call to those functions, make them all match.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 10:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 08:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

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