I Have a Problem in following code
#include<stdio.h>
#include<stdlib.h>
struct linked
{
    int val;
    struct linked *before;
    struct linked *next;
};
void get(struct linked *var);
void printforward(struct linked *var);
void printbackward(struct linked *var);
int main()
{
    struct linked *ptr,*temp;
    ptr=(struct linked*)malloc(sizeof(struct linked));
    if(ptr==NULL)
    {
        printf("NOT ENOUGH MEMOREY");
        exit(2);
    }
    ptr->before=NULL;
    get(ptr);
    printf("\nForward:\n");
    printforward(ptr);
    for(temp=ptr;temp->next;temp=temp->next)
    {
        temp->next->before=(struct linked*)temp;
    }
    printf("\nBackward:\n");
    printbackward(temp->before);
 }
void get(struct linked *var)
 {
    printf("Enter the number (-99) to quit:");
    scanf("%d",&var->val);
    if(var->val==-99)
    {
         var->next=NULL;
         return;
     }
   else
   {
        var->next=(struct linked*)malloc(sizeof(struct linked));
        if(var->next==NULL)
        {
            printf("NOT ENOUGH MEMOREY");
            exit(2);
         }
         get(var->next);
   }
}
void printforward(struct linked *var)
{
    if(var->next==NULL)
   {
       return;
   }
   else
    {
        printf("\n%d",var->val);
        printforward(var->next);
    }
}
 void printbackward(struct linked *var)
 {
     if(var->before==NULL)
     {
         printf("\n%d",var->val);
         return;
     }
     else
     {
         printf("\n%d",var->val);
         printforward(var->before);
     }
    }
output:
 Enter the number (-99) to quit:1
 Enter the number (-99) to quit:2
 Enter the number (-99) to quit:3
 Enter the number (-99) to quit:4
 Enter the number (-99) to quit:5
 Enter the number (-99) to quit:6
 Enter the number (-99) to quit:7
 Enter the number (-99) to quit:8
 Enter the number (-99) to quit:9
 Enter the number (-99) to quit:0
 Enter the number (-99) to quit:-99
Forward:
1
2
3
4
5
6
7
8
9
0
Backward:
0
9
0
Process returned 0 (0x0)   execution time : 22.297 s
Press any key to continue.
Expected output:
Enter the number (-99) to quit:1
Enter the number (-99) to quit:2
Enter the number (-99) to quit:3
Enter the number (-99) to quit:4
Enter the number (-99) to quit:5
Enter the number (-99) to quit:6
Enter the number (-99) to quit:7
Enter the number (-99) to quit:8
Enter the number (-99) to quit:9
Enter the number (-99) to quit:0
Enter the number (-99) to quit:-99
Forward:
1 
2
3
4
5
6
7
8
9
0
Backward:
0
9
8
7
6
5
4
3
2
1
Let me know What's problem in the code,I am learning linked list in c language,I want to write a code for double way linked list But I a have a logical error in above problem,I did not get clear idea Why The above code did not work,so I am request to clear the doubt.
 
    