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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

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,414 ✭✭✭✭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