Always get the error code. I'm trying to reverse transverse the list and print. Is there something I'm missing in the creation of the list? I can print the list normal but just not reversed Any help would be appreciated
struct stNode {
char *pName;
double avg;
struct stNode *next;
struct stNode *prev;
}; //stNode
typedef struct stNode Node;
void createList(Node **head, Node **tail) {
Node* tmp;
Node* x;
for(int i = 0;i < INPUTSIZE; i++){
//stores values in nodes
tmp = malloc(sizeof(Node));
tmp->avg = f1input_avg[i];
tmp->pName = f1input_name[i];
tmp->next = NULL;
//If list is empty
if( *head == NULL){
*head = tmp;
}
//Creates subsequent nodes
else{
x = *head;
while(x->next != NULL){
x = x->next;
}
x->next = tmp;
}
}
} // createList
void RevprintList(Node *head){
Node *cur = NULL;
printf("=======Reversed List =======\n");
cur = head;
while (cur->next != NULL) {
cur = cur->next;
}
while (cur != head){
printf("%-15s %5.2lf\n", cur->pName, cur->avg);
cur = cur->prev;
}
}
int main() {
Node *head = NULL;
Node *tail = NULL;
createList(&head, &tail);
printList(head);
RevprintList(head);
freeList(&head, &tail);
}
Process returned -1073741819 (0xC0000005)
User contributions licensed under CC BY-SA 3.0