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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:42:20+00:00 2026-05-27T03:42:20+00:00

I am writing to a binary file using a struct that just contains a

  • 0

I am writing to a binary file using a struct that just contains a char[32]. I basically need to format each block of data by performing various calculations on string arrays and concatenating the results. I am attempting to copy an std::string to a char array with no null termination. The more I read into this, the more confused I get. If I do:

struct block{
    char data[32];
};
block blocks[2048];
std::string buffer;

buffer = "12345678123456781234567812345678";
strcpy(blocks[0].data, buffer.c_str());

I get an error, because adding the null terminator with c_str() makes the string length 33. If I subtract one char from the string, it works, but then I have the null terminator, which I don’t want. I can successfully do the following:

strcpy(blocks[0].data, "12345678123456781234567812345678");

but I want to construct the string first, since it often involves concatenating different strings from various arrays. For instance, I can do this with std::string:

std::string buffer = stringArray1[0] + stringArray2[0];
strcpy(blocks[0].data, buffer.c_str());

but then I have the null terminator again. I’d just like to copy exactly the chars in the std::string with no null terminator.

I am using VC++ 6.0.

  • 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-27T03:42:20+00:00Added an answer on May 27, 2026 at 3:42 am

    Use memcpy instead of strcpy, that’s what it’s there for:

    memcpy(blocks[0].data, buffer.data(), sizeof(blocks[0].data)); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a class that compresses binary data using a zlib stream. I
I am writing to binary file using fstream and when open the file using
I am writing the below structure in to the file using Binary Writer. File
Using a very large raw binary data file, I will be creating a large
I'm getting data from a binary file, reading from file and writing in a
I have a Base64 encoded String that contains PDF data. Using the EncdDecd unit
I'm writing a Binary file converter in which I need to convert 1-6 byte
I'm creating a binary file to transmit to a third party that contains images
I am working with Delphi Prism and creating and writing into binary file using
I'm writing a cross-platform package which need to include different binary file for different

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.