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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:52:59+00:00 2026-05-28T19:52:59+00:00

I have a file in which I read in data. Suppose the file has

  • 0

I have a file in which I read in data. Suppose the file has the string “abcdefghij”. Now, I’m going to be reading from the file at random times from different processes and they store that byte and offset somewhere. For instance, I save ‘c’ as my character with an offset of ‘3’ because that is its location. For reference, I’ve been using lseek to get the offset in my files.

Next, I want to write this to a new file. Is it possible to write to a specific offset in an empty file? So, I want to write ‘c’ to position ‘3’ in the file and then another process will write ‘j’ to the file at position 10.

  • 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-28T19:53:00+00:00Added an answer on May 28, 2026 at 7:53 pm
    #include <stdio.h>
    
    int main ()
    {
        FILE * f = fopen ("/tmp/x.txt", "w");
    
        fseek (f, 3, SEEK_SET);
        fwrite ("c", 1, 1, f);
    
        fseek (f, 10, SEEK_SET);
        fwrite ("j", 1, 1, f);
    
        fclose (f);
    }
    

    When this runs, the hexdump of /tmp/x.txt is

    00 00 00 63 00 00 00 00  00 00 6a          | ...c.... ..j
    

    fseek is based on lseek which is capable of recognising “holes” in files (ranges of zeroes which haven’t been written yet) but the underlying file system needs to support this.

    It’s not brilliantly clear to me from the manpage that the holes are strictly required to be zeroes, but that seems to be the case in practice.

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

Sidebar

Related Questions

I have an xml file(from federal government's data.gov) which I'm trying to read with
Suppose I have a 400K text file which I want to read from a
I have dynamic array filled with bytes, which are read from .raw file with
I have .zip file which contain csv data. I am reading .zip file using
Suppose you are working with some data, which comes from a JSON file. You
I have text file from which I need to get data by line by
I have an Excel file from which I have to extract the required data
I have a file which is an XML representation of some data that is
I have a file which has multiple columns, whitespace separated. e.g: data1 data2 data3
Assume you have a file which has been committed in your Git repo. You

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.