I just got into structs and I decided to create a list using them:
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
char counter;
struct list
{
int x;
struct list *pointer1;
};
struct list test;
struct list *pointer2;
pointer2=&test;
for(counter=0;counter<5;counter++)
{
pointer2->pointer1=malloc(sizeof(struct list));
pointer2=pointer2->pointer1;
}
}
I was wondering if there is another way to do the exact same thing. Is the use of one pointer only possible? By the way, I am pretty sure I could do the same thing using an array of structs too. Any advice would be really helpful!