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 8603643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:22:20+00:00 2026-06-12T02:22:20+00:00

I have a data structure in c that is an array of struct pointers:

  • 0

I have a data structure in c that is an array of struct pointers:

struct trex *trex_arr[128];

struct trex{
    struct trex *next;
    char name[LEN];
    unsigned int id; 
    int groups[LEN];
    struct list *filenames; //linked list
    unsigned int fn_len;
};

I want to write the array to file. I understand that I need to write the object in the “next” pointer and each element in the linked list as well, but how do I do it so that I can read it back successfully into my original array (there is chaining in the array as well)?

  • 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-06-12T02:22:22+00:00Added an answer on June 12, 2026 at 2:22 am

    Offhand, the simplest way to do it is to write the structure out sequentially so that:

    [trex item #1]
    [list item #1]
    [list item #2]
    [list item #3]
    [trex item #2]
    [list item #1]
    [list item #2]
    [list item #3]
    [list item #4]
    etc...
    

    (Of course, this is just sort of the jist of it. These are binary writes and this is a visual only.)

    I’m hoping that fn_len describes the number of items in the linked list struct list *filenames. If so, this is a snap.

    On writing:

    1. Write out the first structure in the trex linked list
    2. Loop and write out the struct list *filenames from that first trex structure one at a time
    3. Repeat #1 with the next item in the trex linked list until the list is exhausted.

    On reading, remember: all of your pointers are going to be worthless initially. You have to stitch them together yourself. But the structures are arranged in the correct order in the file.

    1. Read the first trex structure. You know its size, reading it isn’t a problem. Fix the next pointer to nothing.
    2. Loop and read each of the struct list *filenames one at a time. You know how many they are because of fn_len in the structure you just read. Stitch together that linked list and attach it to the trex structure.
    3. Repeat #1 with the next trex structure until EOF, join the structure onto the end of the linked list as appropriate.

    And that should take care of it.

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

Sidebar

Related Questions

I have a structure called Patch that represents a 2D array of data. newtype
we have a data structure struct MyData { int length ; char package[MAX_SIZE]; };
I have to design a data structure that is to be used in a
If I have a requirement to create a data structure that has the following
I have a problem here that requires to design a data structure that takes
I have a JSON-like data structure (which I don't want to change) that is
I have the need to use a Stack-like data structure for a program that
I have a structure in my program that contains a particular array. I want
I have a C structure that looks like this typedef struct event_queue{ Event* event;
I have a struct that's inside an array that is nested inside another struct,

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.