Hi!
I believe it must be quite simple to do, and I'm not finding it on the forum. I'd like to access a specific variable in my code which is in a Linked List.
I've tried to use something like struct_name[position].variable_name, but It's not working. On the code below, I tried to print its value...
What am I supposed to do?
Code:
#include <stdio.h>
#include <stdlib.h>
struct list {
int info;
struct list* next;
};
typedef struct list List;
List* initialize (void)
{
return NULL;
}
List* insert (List* l, int i)
{
List* new = (List*) malloc(sizeof(List));
new->info = i;
new->next = l;
return new;
}
void print (List* l)
{
List* p;
for (p = l; p != NULL; p = p->next)
printf("info = %d\n", p->info);
}
int main(int argc, char *argv[])
{
l = initialize();
l = insert(l, 23);
l = insert(l, 45);
print(l);
printf("%d\n",l[0].info); //<------------------------ Here
system("PAUSE");
return 0;
Thanks =)