saving and loading a linked list to a binary file (C)
<p>I'm trying to write and read a linked list from a binary file in C.
My aim is saving and loading resident data for a Nursing Home (actually, I'm a Nurse), in order to classify each resident via the Resource Utilization Groups. I've already done it for a fixed amount of residents (32, that is the capacity of the facility) using an array of structures, but now I need to do so for a variable set of residents, in order to do a statistic study. 
Obviously for this first attempt i simplified the structure to the minimum, as the actual structure contains 109 data.</p>

<p>I'm very close to the solution but something doesn't work, that is, each element of the saved list is alternated with a void one.This code should read the list from the binary file, show it on the terminal, add a new element, save the list. Of course each procedure should be put in a function.</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;ncurses.h&gt;

struct pat
{
    char surn [16];
    char name [16];
    struct pat *next;
};

static FILE *h;
static struct pat *osp;
static struct pat *first;

struct pat *make_structure (void);

int main()
{
    initscr();
    raw();
    keypad (stdscr, TRUE);
    noecho();

    clear();

    osp=make_structure();
    first=osp;

    h=fopen ("archivio","r");

    if (h==NULL)
        printw ("Archivio inesistente\n");
    else
    {
        while (!feof(h))
        {
            printw ("Lungh. nome = %d\n",sizeof osp-&gt;name);
            fread (osp-&gt;surn,sizeof osp-&gt;surn,1,h);
            fread (osp-&gt;name,sizeof osp-&gt;name,1,h);
            printw ("Cognome: %s\tNome: %s\n",osp-&gt;surn,osp-&gt;name);
            osp-&gt;next=make_structure();
            osp=osp-&gt;next;
        }
    }

    getch();

    echo();
    printw ("Surname: ");
    scanw ("%s",osp-&gt;surn);
    printw ("\nName: ");
    scanw ("%s",osp-&gt;name);

    noecho();

    osp=first;

    h=fopen ("archivio","w");

    while (osp != NULL)
    {
        fwrite (osp-&gt;surn,sizeof osp-&gt;surn,1,h);
        fwrite (osp-&gt;name,sizeof osp-&gt;name,1,h);
        osp=osp-&gt;next;
    }

    return 0;
}

struct pat *make_structure(void)
{
    struct pat *a;
    a = (struct pat *)malloc(sizeof(struct pat));
    return (a);
}
</code></pre>