Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Linked List quesition (C++)

  • 24-05-2002 12:19PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 16,415 ✭✭✭✭Trojan


    roffle...

    Thanks for that DBC.

    Anyone else want to reply before this gets locked?

    Al.


  • Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 2,281 ✭✭✭DeadBankClerk


    it does save the whole object.

    // Look at me!
    sizeof(node)


  • Advertisement
  • Registered Users, Registered Users 2 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