I am fairly new to C but have been asked by my teacher to implement a linked list.
When I ran the code below in Repl.it it works, however when I running it on my machine with gcc on windows, it doesn't exit the while loop.
Any ideas?
#include <stdio.h>
#include <stdlib.h>
struct node *newNode(int);
void llAppend(int);
void llPrint(void);
struct node {
int data;
struct node *next;
};
struct node *ll;
int main(void) {
llAppend(2);
llAppend(3);
llPrint();
}
struct node *newNode(int data) {
struct node *tmp;
tmp = malloc(sizeof (struct node));
tmp->data = data;
return tmp;
}
void llAppend(int data) {
struct node *tmp;
if (ll == NULL) {
ll = newNode(data);
return;
}
tmp = ll;
while (tmp->next != NULL) {
tmp = tmp->next;
}
tmp->next = newNode(data);
}
void llPrint(void) {
struct node *tmp;
tmp = ll;
while (tmp != NULL) {
printf("%d\n", tmp->data);
tmp = tmp->next;
}
}