Thanks for any help. Most of this works, but I get a compiler error on lines 60, 84, and 105, where it says
current = currentStore->link
The error reads "assignment from incompatible pointer type" It runs, but in the printStores function when i gets incremented on line 81 it changes from 0 to 3 (debug watch) instead of 1 and then it only prints the first store and exits the for loop. I'd appreciate any help I can get. I already asked my teacher and she told me it looks right. I've tried on 1 linux and two windows computers with the same result.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define STORE_NAME_SIZE 35
#define STORE_PHONE_SIZE 8
int storeCount = 0;
int searchTarget = 0;
typedef struct
{
int storeNumber;
char storeName[STORE_NAME_SIZE];
char phoneNumber[STORE_PHONE_SIZE];
struct STORE *link;
}STORE;
typedef struct
{
STORE *head;
int count;
}LINKEDLIST;
/* ************************************************************************************ */
LINKEDLIST *createList()
{
LINKEDLIST *list = malloc(sizeof(LINKEDLIST));
list->head = NULL;
list->count = 0;
return list;
}
/* ************************************************************************************ */
STORE *createVacantStore()
{
STORE *newVacantStore = malloc(sizeof(STORE));
storeCount++;
newVacantStore->storeNumber = storeCount;
strcpy(newVacantStore->storeName, "vacant");
strcpy(newVacantStore->phoneNumber, "000-0000");
newVacantStore->link = NULL;
return newVacantStore;
}
/* void printList(VACANTLIST *list); */
/* ********************************************************************************************** */
STORE *addVacantStore(LINKEDLIST *list)
{
STORE *currentStore;
STORE *store;
store = createVacantStore();
if (list->head == NULL)
{
list->head = store;
}
else
{
currentStore = list->head;
char *test = currentStore->storeName;
printf("%s\n\n\n", test);
while (currentStore != NULL)
{
currentStore = currentStore->link;
}
currentStore = store;
}
list->count++;
return currentStore;
}
/* ****************************************************************************************** */
void printStores(LINKEDLIST *list)
{
int i = 0;
STORE *currentStore;
int j = list->count;
if (list->head == NULL)
{
printf("The list is empty");
}
currentStore = list->head;
//printf("%s", currentStore->storeName);
for(i = 0; i < j; i++);
{
printf("%d\t%s\t%s\n", currentStore->storeNumber, currentStore->storeName, currentStore->phoneNumber);
currentStore = currentStore->link;
}
}
/* **************************************************************************** */
void printIndividualStore(STORE *currentStore)
{
printf("%d\t%s\t%s\n", currentStore->storeNumber, currentStore->storeName, currentStore->phoneNumber);
}
/* **************************************************************************** */
STORE *searchStore(int searchTarget, LINKEDLIST *list)
{
STORE *currentStore;
if (list->head != NULL)
{
currentStore = list->head;
while (currentStore != NULL && currentStore->storeNumber != searchTarget)
{
currentStore = currentStore->link;
}
if (currentStore->storeNumber == searchTarget)
{
return currentStore;
}
}
return NULL;
}
/* **************************************************************************** */
int main()
{
//STORE *store;
LINKEDLIST *vacantList;
LINKEDLIST *occupiedList;
vacantList = createList();
occupiedList = createList();
addVacantStore(vacantList);
addVacantStore(vacantList);
addVacantStore(vacantList);
printStores(vacantList);
/* searchTarget = 2;
store = searchStore(searchTarget, vacantList);
printIndividualStore(store); */
return 0;
}