I'm writing a c code in order to dynamically create a sturcture like this:

1st -> 5 -> 7 -> 2, then 2->5(there is an arrow beneath 2 and link it back to 5)

the data is below:

struct node {
        int value;
        struct node *next;
     }

Here is what I have so far, did I go wrong somewhere?

 void insert(node *pointer, int value)
    {
    node *start = pointer;
/* Iterate through the list till we encounter the last node.*/
while(pointer->next!=start)
   {
    pointer = pointer -> next;
   }
  /* Allocate memory for the new node and put value in it.*/
     pointer->next = (node *)malloc(sizeof(node));
     pointer = pointer->next;
     pointer->value = value;
     pointer->next = start;
   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.