load data from file in c language
<p>I'm a beginner. I made a program to load and save data in a binary file, when pressing a load button. But the data displayed in the file is just rubbish data.</p>

<pre><code>#include &lt;stdio.h&gt;
#define size 5
#define enter 13
#define esc 27 
#define home 71
#define end 79
#define up 72
#define down 80

struct node {
    int id;
    char name[30];
    struct node* prev;
    struct node* next;
};

struct node* head = NULL;
struct node* tail = NULL;

void save_to_file();
void display_list();
void append_node(struct node* temp);
struct node* create_node_from_file(int id, char name[]);
struct node* create_node();
int check_for_id(int id);
struct node* search_by_id(int s);
load_from_file() ;

void main ()
{
    char ch;
    int flag = 0, i, num;
    int pos = 0;
    char word[5][30] = {"add", "Display", "Save", "Load", "Exit"};
    struct node* t;
    int id;
    char searchname[30];

    clrscr();
    do
    {
        clrscr();
        for(i = 0; i &lt; 5; i++)
        {
            gotoxy(10, 5 + i);
            if(i == pos)
            {
                textattr(0x70);
            }
            cprintf("%s", word[i]);
            textattr(0x07);
        }
  //    textattr(0x06);
        ch = getch();
        switch(ch)
        {
            case enter:
                clrscr();
                switch(pos)
                {
                    case 0:
                        t = create_node();
                        append_node(t);
                        printf("\n\t\tInsertion succeessful !");
                        break;
                    case 1:
                        display_list();
                        break;
                    case 2:
                        save_to_file();
                        break;
                    case 3:
                        load_from_file();
                        break;
                    case 4:
                        printf("exit");
                        flag = 1;
                        break;
                }

            case NULL:
                ch=getch();
                switch(ch)
                {
                    case home:
                        pos = 0;
                        break;
                    case end:
                        pos = 4;
                        break;
                    case up:
                        pos--;
                        if(pos &lt; 0)
                            pos = 4;
                        break;
                    case down:
                        pos++;
                        if(pos &gt; 4)
                            pos = 0;
                        break;
                }
                break;
        }
     } while(flag !=1);
     getch();
}

struct node* create_node() {
    struct node* temp;
    int tryid;
    int t;
    int flag = 0;

    temp = (struct node*)malloc(sizeof(struct node));
    while(flag != 1) {
        printf("\n\tPlease Enter Id: ");
        scanf("%d", &amp;tryid);
        t = check_for_id(tryid);
        if(t == 0) {
            temp-&gt;id = tryid;
            flag = 1;
        }
        else
            printf("\nId %d already exists!", tryid);
    }
    printf("\n\tPlease Enter Name: ");
    flushall();
    gets(temp-&gt;name);
    temp-&gt;prev = NULL;
    temp-&gt;next = NULL;
    return temp;
}

int check_for_id(int id) {
    struct node* ptr;
    ptr = search_by_id(id);
    if(ptr != NULL)
        return 1;
    return 0;
}

struct node* search_by_id(int s) {
    struct node* ptr;
    ptr = head;
    while(ptr != NULL) {
        if(ptr-&gt;id == s)
            return ptr;
        ptr = ptr-&gt;next;
    }
    return NULL;
}

struct node* create_node_from_file(int id, char name[]) {
    struct node* temp;
    temp = (struct node*)malloc(sizeof(struct node));
    temp-&gt;id = id;
    strcpy(temp-&gt;name, name);
    temp-&gt;prev = NULL;
    temp-&gt;next = NULL;
    return temp;
}

void append_node(struct node* temp) {
    if(head == NULL) {
        head = temp;
        tail = temp;
    }
    else {
        tail-&gt;next = temp;
        temp-&gt;prev = tail;
        tail = temp;
    }
}

void display_list() {
    struct node* temp;
    //sort();
    temp = head;
    if(head == NULL &amp;&amp; tail == NULL) {
        printf("\n\tList is Empty!\n\t\tNo Data..");
        return;
    }
    while(temp != NULL) {
        printf("\n%d", temp-&gt;id);
        printf("\t\t\t%s\n", temp-&gt;name);
        temp = temp-&gt;next;
    }
    return;
}

void save_to_file(struct node emp) {
    int id;
    int index=0;
    char name[30];
    struct node* ptr;
    FILE* fp;
    //sort();
    ptr = head;
    fp = fopen("file.bin", "wb"); //open file for writing
    while(ptr != NULL) {
        fwrite(ptr,sizeof(*ptr), 2, fp);
        ptr = ptr-&gt;next;
    }
    fclose(fp);
    gotoxy(30,10);
    printf("Data saved to file.");
    return;
}

load_from_file()
{
    struct node emp;
    FILE *fptr;
    fptr = fopen("file.bin", "rb");
    while(feof(fptr) == NULL)
    {
        fread(&amp;emp, sizeof(emp), 1, fptr);
        printf("%d  %s", emp.id, emp.name);
        printf("\n");
    }
    fclose(fptr);
   //   rewind(fptr);
} 
</code></pre>

<p>What is the problem with the code? And how can I change it?</p>