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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:53:53+00:00 2026-05-26T04:53:53+00:00

bool CReadWrite::write(unsigned long long offset, void* pvsrc, unsigned long long nbytes) { int WriteResult;

  • 0
bool CReadWrite::write(unsigned long long offset, void* pvsrc, unsigned long long nbytes)
{   int WriteResult;

    pFile = fopen("D:\\myfile.bin","wb");

    if (!pFile){   
        puts("Can't open file"); 
        return false;
    }

    //offset = fseek(pFile,offset,

    WriteResult = fwrite (pvsrc, 1, nbytes, pFile);

    if (WriteResult == nbytes){   
        puts("Wrote to file");
        fclose(pFile);
        return true;
    }
    else{   
        puts("Unable to write to File."); 
        fclose(pFile);
        return false;
    }   
}

This is my class function so far. I’m basically opening a file, checking to see if it did indeed open if not get out. Writes the file, checks to see if the file see if the file was indeed written to returns true. else return false. As you can tell by my parameters, I’m looking to create an offset where I can give a particular offset i.e. 10, and start from 10 and then from there write. I know for sure I need to use fseek but I can’t assume that I’m at the beginning of the file or anywhere in the file. Im pretty sure i need to use SEEK_SET but I may be wrong. Any thoughts on implemented the above desires? Thanks.

  • 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-26T04:53:53+00:00Added an answer on May 26, 2026 at 4:53 am

    If you’re using fopen without the append setting (as you are, “wb” creates an empty file), you can assume you’re at the beginning.

    Regardless, SEEK_SET sets the position to the given offset from the beginning.

    If the file doesn’t have the offset that you want to seek to (as it is in your case), then the question is what are you required to do? If just pad – then write offset padding bytes, and then your content, otherwise maybe you wanted to use “a” and not “w”. “w” truncates the existing content of the file, while “a” opens for append and sets position to the end of the existing content.

    More details here.

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

Sidebar

Related Questions

bool CReadWrite::write(unsigned long long offset, void* pvsrc, unsigned long long nbytes) { int m_WriteResult;
bool is_something_ok(int param,SomeStruct* p) { bool is_ok = false; // check if is_ok if(is_ok)
bool IsTypeAGenericList(Type listType) { typeof(IList<>).IsAssignableFrom(listType.GetGenericTypeDefinition()) } returns false when given typeof(List<int>) . I assume
bool pred(int k, int l, int num1, int num2) { return (num1 < num2);
// Example bool is true bool t = true; // Convert bool to int
bool fn() { if(something bad happen) return false; .. } void gn() { assert(something
bool stop = false; int f1 = 1; int f2 = 2; int f3
bool binsearch(string phrase, vector<string> words, int from, int to, int &test) { while (tf
bool Win64bit = (sizeof(int*) == 8) ? 1 : 0; I need this so
bool isValid = false; string username = someadmin; If( !String.IsNullOrEmpty(username) && !( username.IndexOf(admin) !=

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.