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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:39:45+00:00 2026-06-11T03:39:45+00:00

I need to create a buffer that contains 300 symbols and pass it to

  • 0

I need to create a buffer that contains 300 symbols and pass it to the function described below:

void printThis(char *info);

What is the best way to generate this buffer?

If this is good:

char *buffer = new char()

then, how to add characters to this buffer? The following method is not good and it raises an access violation:

for (int i=0; i<300;i++)
{
   sprintf(s,"%s",'a');
}
  • 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-06-11T03:39:47+00:00Added an answer on June 11, 2026 at 3:39 am
    std::vector<char> buffer(300, 'a');
    
    // I'm guessing that printThis wants a zero-terminated string
    buffer.push_back(0);
    
    printThis(&buffer[0]);
    

    If you’re using the C++11 library, then buffer.data() might look nicer than &buffer[0].

    If you really want to manage the memory yourself (hint: you don’t), either create an automatic array:

    char buffer[300];
    

    or a dynamic array:

    char * buffer = new char[300];
    
    // Don't forget to delete it, and hope than nothing threw an exception
    delete [] buffer;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I need to create a quickfix buffer listing all lines that match a
I need to write some code that will buffer a line to create a
I need to learn how to handle the char** in the C++ method below
I need to create a cv::Mat from a buffer, but I don't want the
I need to read from a Stream and put the buffer that was read
I need create custom dialog and put JPanel into it. Is it possible?
i need create an email list sending to many emails. what is best solution
I need create clone repository. but I do not know where can I get
I need create a document word with Java. And I ask, how can I
i need create a variable with parent subclass. Example: Parent Class <?php class parentClass

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.