Thread: Saving in a File the Information of a Nested List

  1. #1
    Registered User
    Join Date
    Mar 2016
    Posts
    2

    Saving in a File the Information of a Nested List

    Hey Guys, I am really having a hard time. Because I am making a project and the only part left for me is to save the information of the lists in a FILE

    Code:
    #include <stdio.h>#include <stdlib.h>
    #include <string.h>
    typedef struct consulta{
        float peso;
        char serialvacuna[25]; //Serial of the Vacune
        char tipovacuna[25]; //Type of Vacune
        char diagnostico[250]; //Diagnostic
        char observaciones[250]; //Observations
        char fecha[10]; //Date
        struct consulta *sig;  //Next
    }NODOCONSULTA;
    
    
    typedef struct mascota{
        char nombre[20]; //Name
        char animal[20];
        char nacimiento[10]; //Date of Birth
        char sexo[10]; //Sex
        char raza[20]; //Race
        char color[20]; //Color
        NODOCONSULTA *historialmedico; //Medical History
        struct mascota *sig; //Next
    }NODOMASCOTA;
    
    
    typedef struct cliente{
        char nombre[50]; //Name
        char direccion[100]; //Address
        int cedula; //ID Number
        char telefono[15]; //Phone Number
        NODOMASCOTA *listamascotas; //Pets
        struct cliente *sig; //Next
    }NODOCLIENTE;
    What I need is help or orientation to save all the info in one or more Files.

    Thanks

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Thanks for appending the English translations. It helps the linguistically-challenged like myself.

    Maybe something like the following will work. The idea is to use blank lines to separate different sections with a different number of blank lines between different sections.

    Each field of each node is printed on a separate line. A single blank line follows each node's contents. Two blank lines follow the last node of the mascota list. Three blank lines follow the last node of the consulta list.
    Code:
    Bob Jones
    12345-67st
    other lines
                            <-- single blank line
    fido
    dog
    other lines
                            <-- single blank line
    123.45
    654321
    other lines
                            <-- single blank line
    123.45
    654321
    other lines
                            <-- two blank lines
                            <--
    fido
    dog
    other lines
                            <-- single blank line
    123.45
    654321
    other lines
                            <-- single blank line
    123.45
    654321
    other lines
                            <-- three blank lines
                            <--
                            <--
    Bob Jones
    12345-67st
    other lines
                            <-- single blank line
    fido
    dog
    other lines
                            <-- single blank line
    123.45
    654321
    other lines
                            <-- single blank line
    123.45
    654321
    other lines
                            <-- two blank lines
                            <--
    fido
    dog
    other lines
                            <-- single blank line
    123.45
    654321
    other lines
                            <-- single blank line
    123.45
    654321
    other lines
                            <-- three blank lines
                            <--
                            <--

  3. #3
    Registered User
    Join Date
    Mar 2016
    Posts
    2
    Thank you for your answer. In the case I need to use fopen and fclose to store the information in a .txt or wb file? What should I do

  4. #4
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Quote Originally Posted by José Aguilera View Post
    Thank you for your answer. In the case I need to use fopen and fclose to store the information in a .txt or wb file? What should I do
    You would fopen the file with "w" mode (for writing a text file).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Saving information from a structure to a file
    By teensicle in forum C Programming
    Replies: 14
    Last Post: 11-14-2011, 08:46 AM
  2. Saving Linked List
    By Blacky Ducky in forum C++ Programming
    Replies: 11
    Last Post: 06-15-2011, 01:56 AM
  3. Nested for loop...search & display a list within a list
    By chadsxe in forum C++ Programming
    Replies: 13
    Last Post: 07-20-2005, 01:34 PM
  4. saving/reading information to/from a .txt using C++..
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 08-31-2002, 01:23 PM
  5. Saving information
    By bluehead in forum C++ Programming
    Replies: 5
    Last Post: 01-08-2002, 06:15 PM