Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Linked List quesition (C++)

Options
  • 24-05-2002 1:19pm
    #1
    Registered Users Posts: 7,314 ✭✭✭


    Anyone know a suitable method of saving a linked list?
    is the best method to just loop through the list when i want to save and change it to an easily saveable format?


Comments

  • Registered Users Posts: 2,281 ✭✭✭DeadBankClerk


    Originally posted by Serialkiller
    i can do plenty thanks very much......wanker....

    [php]
    #include <stdio.h>
    size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
    ptr
    Points to the buffer that is to hold the data written.
    size
    Is the size of one of the elements to be written.
    nitems
    Is the number of elements to be written.
    stream
    Points to the output stream.
    [/php]

    [php]
    // pseudo code
    write to disk length of list // i don't know the syntax
    // possible use writec to write a char
    // using a 4 byte union with int?

    // a temp node for writing to disk
    node* ioNode;
    ioNode = firstNode;

    while (true)
    {
    // write node to disk
    fwrite(ioNode, sizeof(node), 1, myFile);

    // get next node
    ioNode = ioNode.next;

    // if (end of list)
    if (!ioNode) break;
    }
    [/php]


  • Registered Users Posts: 16,413 ✭✭✭✭Trojan


    roffle...

    Thanks for that DBC.

    Anyone else want to reply before this gets locked?

    Al.


  • Registered Users Posts: 2,281 ✭✭✭DeadBankClerk


    [php]

    union four_byte
    {
    int intgr;
    char byte[4];
    }

    four_byte size = nodeCount;
    fwrite(&size, 1, 4, myFile);

    // Or maybe
    fwrite(&nodeCount, 4,1, myFile);
    [/php]


  • Registered Users Posts: 7,314 ✭✭✭Nietzschean


    thanks marc u big baby u..........i tried something similar before but my attempt involved trying to save the overall object...which failed miserbly :) ty anyway


  • Registered Users Posts: 2,281 ✭✭✭DeadBankClerk


    it does save the whole object.

    // Look at me!
    sizeof(node)


  • Advertisement
  • Registered Users Posts: 7,314 ✭✭✭Nietzschean


    maybe yours does..i haven't gotten a chance to try it yet. but my similar effort ended in vein, couldn't calculate size of the object as a result of all the links and that but i see your code has over come that :)


Advertisement