Okay I have updated my code quite a bit. I am getting a new problem, but it seems to be on a correct path. Now when I enter in the numbers it just continually spits out the first number I entered instead of moving to the next number.
main.c
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <cType.h>
#include "list.h"
#define amount 3
//Prototypes
void printList(LIST* number);
int main(){
int i;
int* dataPtr;
int number;
LIST* numberList;
numberList = createList();
printf("Please enter %d numbers for the linked list\n", amount);
for(i = 0; i < amount; i++){
printf("#%d: ", i+1);
scanf("%d", &number);
dataPtr = malloc(sizeof(int));
*dataPtr = number;
addNode(numberList, dataPtr);
}
printList(numberList);
system("PAUSE");
return 0;
}
void printList(LIST* number){
int* dataPtr;
while (!emptyList(number)){
traverse(number,0, (void*)&dataPtr);
printf("%d\n", *dataPtr);
addNode(number, dataPtr);
}
}
list.h
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <cType.h>
//List ADT Type Definitions
typedef struct node{
void* dataPtr;
struct node* link;
} NODE;
typedef struct{
int count;
NODE* pos;
NODE* head;
NODE* rear;
} LIST;
//Prototype Declarations
LIST* ceateList(void);
bool traverse (LIST* pList, int fromWhere, void** dataOutPtr);
int listCount (LIST* pList);
bool emptyList (LIST* pList);
bool fullList (LIST* pList);
bool addNode (LIST* pList, void* dataInPtr);
list.c
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <cType.h>
#include "list.h"
LIST* createList(void){
LIST* list;
list = (LIST*) malloc (sizeof(list));
if(list){
list->head = NULL;
list->rear = NULL;
list->count = 0;
}
return list;
}
bool addNode(LIST* pList, void* dataInPtr){
NODE* pNew;
if(!(pNew = (NODE*) malloc(sizeof(NODE))))
return false;
pNew->dataPtr = dataInPtr;
pNew->link = NULL;
if(pList->count == 0){
pNew->link = pList->head;
pList->head = pNew;
if(pList->count == 0)
pList->rear = pNew;
}
else{
pNew->link = pNew;
if(pNew->link == NULL)
pList->rear = pNew;
}
(pList->count)++;
return true;
}
bool emptyList(LIST* pList){
return(pList->count == 0);
}
bool fullList(LIST* pList){
NODE* temp;
if((temp = (NODE*)malloc(sizeof(*(pList->head))))){
free(temp);
return false;
}
return true;
}
int listCount(LIST* pList){
return pList->count;
}
bool traverse(LIST* pList, int fromWhere, void** dataPtrOut){
if(pList->count == 0)
return false;
if(fromWhere == 0){
pList->pos = pList->head;
*dataPtrOut = pList->pos->dataPtr;
return true;
}
else{
if (pList->pos->link == NULL)
return false;
else{
pList->pos = pList->pos->link;
*dataPtrOut = pList->pos->dataPtr;
return true;
}
}
}