generating *char buffer

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');
}

Answers


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;

Need Your Help

WCF/WPF best practice - WCF ChannelFactory and PRISM

wpf wcf prism channelfactory

I'm new to the PRISM framework so my question may be a bit off topic.

Could not load type 'AjaxControlToolkit.Sanitizer.AntiXssSanitizerProvider'.

c# asp.net webforms ajaxcontroltoolkit

I tried to use htmleditorextender but I am getting error. below are my settings

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.