Functions for dynamic memory allocation in C++ -


i'm trying set generic functions in c++ allocate memory dynamically, , got far:

char* init_char(uint64_t a, const char* init){   char* ptr = new char[a];   memset(ptr, '\0', a*sizeof(char));    if(init != null)     strcpy(ptr, init);    return ptr; }  char** init_char(uint64_t a, uint64_t b, const char* init){   char** ptr = new char*[a];   for(uint64_t = 0; < a; a++)     ptr[a] = init_char(b, init);    return ptr; } 

the idea pass dimensions (a, b) , initialization string (init) , return array memory allocated. however, while first 1 seems work properly, second 1 returns null pointer.

i've looked around no good. in other post (function dynamic memory allocation) seem quite similar. missing here?

thanks,

your error not use c++.

your problem can reduced to:

std::string initstr("initialitation string"); int = 10;  std::vector<std::string> mystringarray(a, initstr); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -