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*/