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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:48:01+00:00 2026-05-18T01:48:01+00:00

I have a significant amount of data being generated in a C program. I

  • 0

I have a significant amount of data being generated in a C program. I want to write the data out into 1gb files.

How would I got about doing this?

At the moment, I go through a while loop (with a condition that will go on until 5 gbs data is created). It creates a struct and writes it to a file:

fwrite(storedVal, sizeof(keyEncode),1,fp);
//storedVal being the struct (which contains my data)

I would like each file to be called codes1, codes2 and increment on until the while loop is finished. I am sure it would include an if statement based on the size of the current file it is writing to. Then when it reaches 1gb, it begins on a new file.

edit //

actually it should be some sort of while statement , that keeps writting to the size, untill the file reaches 1gb and starts on the new one

My file at the moment is opened prior to my while loop:

fp = fopen("keys.dat", "wb");
while(condition is true) {
    //create a new struct with data and
    fwrite(storedVal, sizeof(keyEncode),1,fp);
}
  • 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-18T01:48:01+00:00Added an answer on May 18, 2026 at 1:48 am

    Something along the lines of the following – note that there are some parts left out to fill in.

    int write_count = 0;
    int file_idx = 1;
    FILE *fp;
    char filename[20];
    
    sprintf( filename, "codes%d", file_idx );
    file_idx++;
    fp = fopen(filename, "wb");
    
    while( foo ) {
    
        //update data
    
        if( write_count + sizeof(keyEncode) > ONE_GIGABYTE ) {
            fclose(fp);
            write_count = 0;
            sprintf( filename, "codes%d", file_idx );
            file_idx++;
            fp = fopen(filename, "wb");
        }
    
        fwrite(storedVal, sizeof(keyEncode),1,fp);
        write_count += sizeof(keyEncode);
    }
    
    fclose(fp);
    

    Update

    You could incorporate logic like this into a helper function to write, as per Aaron’s response. Note that you would have to make some of the data members global and it would not be thread safe.

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

Sidebar

Related Questions

I have several files out on a server which my user downloads into their
I have a program in which significant amount of time is spent loading and
I have a PHP file that writes a significant amount of data to a
I have a web app that manages a significant amount of project data. I
I have about 6500 files for a sum of about 17 GB of data,
I have an application running in IIS (ASP.NET) and a significant amount of times,
I have a significant number of object libraries written for PHP 5.2.5, and I'm
Does COUNT(*) have any significant impact for MySQL performance if query already has GROUP
I am told that the configuration below is possible, but have had significant difficulty
I have seen lot projects following this kind of coding style Any significant advantage

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.