Thread: Saving linked lists to a binary file

  1. #1
    Registered User
    Join Date
    Apr 2008

    Question Saving linked lists to a binary file

    I'm trying to do the code to store a linked list to a binary file.

    My strutures are:
    typedef struct
    	char nome[25];
    	Coordenadas localizacao;
    	char morada[100];
    	char email[25];
    	char tipoComida[25];
    	Data feriasInicio;
    	Data feriasFim;
    	int diaDescanso;
    	char periodoFerias[25];
    	int numeroTelefone;
    } Restaurante;
    typedef struct No
    	Restaurante* restaurante;
    	struct No* proximo;
    } No;
    I'm not sure if I can simply store the No structs since they have only pointers. I already did a first try and the code does not work properly and doesn't always have the same behaviour so I'm wondering if that's the problem.

    Any ideas?

    Thanks in advance

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    You can't directly write the struct No's to memory, since there's no data there (and even if there was, reading pointers in from files never works, since who knows where the data will be stored this time?) You need to walk the list and write the Restaurantes to a file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Using a linked list globally and File I/O
    By Leftos in forum C Programming
    Replies: 46
    Last Post: 01-07-2008, 11:21 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM