Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 991601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:08:10+00:00 2026-05-16T06:08:10+00:00

is there any standard approach which I’ve missed at school to dump C structure

  • 0

is there any standard approach which I’ve missed at school to dump C structure with nested linked lists on disk in reasonable way?
What I don’t want to do is:

  • use protocol-buffers or any other like serializators,
  • don’t want to create JSON, XML or other

I’ve few ideas:

  • allocate accurate memory amount (or extend existing one) and manage it by myself, placing list elements in stack like approach using some additional fields to manage relative addresses. When necessary dump block on disk. Having procedures to map block from disk create desirable structure being aware of Byte-order.
  • push main structure to file, then push List elements, store information about list in the header of a file.

To image this I’ll give some more details posting example code:

typedef struct{
   int b;
   List *next;
}List;

typedef struct{
   float b;
   List2 *next;
}List2;

typedef struct{
   List *head;
   List *tail;
} info;

typedef struct{
   List2 *head;
   List2 *tail;
} info2;

struct data
{
    int a;
    char t[10];
    info first;
    info second;
    info2 third;
};

cheers
P.

EDIT:

I’ve extended main structure, seems like previous one haven’t indicate the problem fully.
I’m aware that pointers on disk are useless.
Ideas and pseudocode allowed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:08:11+00:00Added an answer on May 16, 2026 at 6:08 am

    Serialize the data in the order it’s held in the linked list, record-style to a file. fwrite is particularly good for this. Be sure to dereference pointers, and be aware of the role endianness plays in this.

    Here’s some vague pseudocode:

    List *list_new();
    List *list_add(List *, void *data);
    List *list_next(List *);
    
    while (node) {
        fwrite(node->data, sizeof(node->data), 1, fp);
        node = list_next(node);
    }
    

    Rough code for reading back into a live list:

    List *node = list_new();
    while (true) {
        struct data *buf = malloc(sizeof(*buf));
        if (1 != fread(buf, sizeof(*buf), 1, fp))
            break;
        list_add(node, buf);
    }
    

    Update0

    If you begin to nest more advanced structures such as other linked lists, variable length strings etc., you’ll need to provide types and lengths for each record, and a way to nest records within other records.

    As an example, if your top level linked list had a data member that was another list, you’d be best to store that member as a nested record, complete with a length, and type field. Alternatively, you could define sentinel records, such as \0 for character strings (an obvious choice), and zeroed blocks for struct data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any standard approach to input data validation and error displaying in GWT+GAE-based
Is there any way of reliably allocating (reserving) hard disk space via standard Java
Is there any standard way to route all Key events from the control A
Is there any standard way of implementing some sort of a write-through buffer for
is there any standard choice of the font family and font size for a
I have a doubt: - Is there any standard/convention that when should I use
Are there any industry standard conventions for naming jar files?
Is there any way I can specify a standard or custom numeric format string
Is there any widely used SQL coding standard out there? SQL is little bit
Is there any class in the .NET framework that can read/write standard .ini files:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.