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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:30:55+00:00 2026-05-11T08:30:55+00:00

Given (in C++) char * byte_sequence; size_t byte_sequence_length; char * buffer; size_t N; Assuming

  • 0

Given (in C++)

char * byte_sequence; size_t byte_sequence_length; char * buffer; size_t N; 

Assuming byte_sequence and byte_sequence_length are initialized to some arbitrary length sequence of bytes (and its length), and buffer is initialized to point to N * byte_sequence_length bytes, what would be the easiest way to replicate the byte_sequence into buffer N times? Is there anything in STL/BOOST that already does something like this?

For example, if the sequence were ‘abcd’, and N was 3, then buffer would end up containing ‘abcdabcdabcd’.

  • 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. 2026-05-11T08:30:55+00:00Added an answer on May 11, 2026 at 8:30 am

    I would probably just go with this:

    for (int i=0; i < N; ++i)     memcpy(buffer + i * byte_sequence_length, byte_sequence, byte_sequence_length); 

    This assumes you are dealing with binary data and are keeping track of the length, not using '\0' termination.

    If you want these to be c-strings you’ll have to allocate an extra byte and add in the '\0' a the end. Given a c-string and an integer, you’d want to do it like this:

    char *RepeatN(char *source, size_t n) {     assert(n >= 0 && source != NULL);                 size_t length = strlen(source) - 1;     char *buffer = new char[length*n + 1];     for (int i=0; i < n; ++i)         memcpy(buffer + i * length, source, length);     buffer[n * length] = '\0'; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 91k
  • Answers 91k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer From my experience with WCF it's quite tough to get… May 11, 2026 at 6:19 pm
  • Editorial Team
    Editorial Team added an answer Its been a while since I played with C, but… May 11, 2026 at 6:19 pm
  • Editorial Team
    Editorial Team added an answer Perhaps you could use the StringOfChar function? Something like this:… May 11, 2026 at 6:19 pm

Related Questions

I have a char (ie. byte) buffer that I'm sending over the network. At
I have been working on a legacy C++ application and am definitely outside of
I'm trying to understand what kind of memory hit I'll incur by creating a
So the teacher has posed this assignment: You have been hired by the United

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.