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');
}
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:
or a dynamic array: