Ok here's a good question. So this is the tutorial on this site for traversing a linked list:
Code:
#include <stdio.h>
#include <stdlib.h>struct node { int x; struct node *next;};int main(){ /* This won't change, or we would lose the list in memory */ struct node *root; /* This will point to each node as it traverses the list */ struct node *conductor; root = malloc( sizeof(struct node) ); root->next = 0; root->x = 12; conductor = root; if ( conductor != 0 ) { while ( conductor->next != 0) { conductor = conductor->next; } } /* Creates a node at the end of the list */ conductor->next = malloc( sizeof(struct node) ); conductor = conductor->next; if ( conductor == 0 ) { printf( "Out of memory" ); return 0; } /* initialize the new memory */ conductor->next = 0; conductor->x = 42; return 0; }
But what if you have this:
Code:
struct node {
char string[80]; struct node *next; };
I put that in the struct, but then pointing to it in the example like this:
Does not work. I'm replacing the int x with the char[80];
Any ideas?