I'm very new to coding in C (and therefore the silly exercise I am working on).
I have a linked list, a function that is supposed to print my linked list, and main function.
Unfortunately my knowledge of C is not good enough to understand why this is not printing. What is even more unfortunate is that this code does not crash.
#include <stdio.h> #include <stdlib.h> typedef struct Node { int data; struct Node* next; } *Node_t; void print_list(Node_t root) { while (root) { printf("%c ", root->data); root = root->next; } printf("\n"); } int main () { int i; int n = 6; Node_t list = (Node_t)malloc(sizeof(struct Node) * n); Node_t root; for (i=0; i < n; i++) { list[i].data = i+1; if (i == n-1) { list[i].next = 0; } else { list[i].next = &list[i+1]; } } root = &(list[0]); print_list(root); }