Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int value;
struct node *next;
} block;
int main(void) {
block *root = NULL;
block *c;
int x;
c = root;
for (x = 0; x < 10; x++) {
c = (block *)malloc(sizeof(block));
c->value = (x*4);
// 0, 4, 8, 12, 16, 20, etc
c = c->next;
}
for (c = root; c; c = c->next)
printf("%d\n", c->value);
return 0;
}
The first for loop is supposed to allocate memory for 10 list items, and assign the value inside the list item to a multiple of four.
The second for loop is supposed to go to the beginning of the list and print each list item.
This program compiles fine, but it doesn't output anything.