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

  • SEARCH
  • Home
  • 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 8546359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:00:01+00:00 2026-06-11T13:00:01+00:00

I was looking at the similar questions but didn’t find a solution . I

  • 0

I was looking at the similar questions but didn’t find a solution .
I have a structure similar to a tree with more than 2 nodes.
I also have a pointer to the root.

typedef struct tree
{
   char *name;
   struct tree *children
}TREE;

I want to write this data to a file , but just got confused so would love to get some help

I thought using :

int writeData(TREE *root , char *filename){

    FILE *f = NULL;
    int numWritten = 0;

fopen_s(&f , filename, "w+" );
fwrite(root , sizeof(TREE) , ??? , f);

}

I don’t know what to write, how can If I have children to every element so I beed to go threw them all – how can I do that?

  • 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-11T13:00:02+00:00Added an answer on June 11, 2026 at 1:00 pm

    Well, this problem is known as ‘serializing structured data’ – basically it’s the opposite of parsing. The thing is that you can’t just dump the raw binary data of your in-memory data structure to a file – it won’t be meaningful upon the next launch of your program when addresses change. You have to come up with a format that is able to describe your data structure and write that to the file. Then, of course, you’ll also have to write a parser for that format if you want to recover the data structure from the file later.

    I suggest using JSON – it’s a lightweight, easy-to-write and easy-to-read data format, and it’s also general-purpose – it’s ideal to store simple abstract data types. Here’s my library that can generate and parse JSON from basic data types (such as arrays, associative arrays, strings, numbers…)

    how can If I have children to every element so I beed to go threw them all

    For this question: you’re probably looking for recursion. You’ll need to recursively traverse your data tree and generate the data representing your data structure as you walk by each node/leaf (assuming your data structure being similar to a graph/tree).

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

Sidebar

Related Questions

I've been looking at similar questions but they are more on how to get
I found similar questions but no answer to what I am looking for. So
I've found some similar questions on StackOverflow, but nothing that addresses what I'm looking
I've found a similar question here , but I'm looking for more general solutions.
I've tried looking at similar problems, but could not easily find one that helped
I have so many similar questions but none of them answers my question.Most are
I've looked at several similar questions but I didn't see any that directly applied
I have asked a similar question before, but didn't get very good results. I've
I have seen & read over 10 similar questions but am still unable to
Okay, I tried to look for similar questions but I didn't understand much of

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.