This piece of code gives me runtime exception: Unhandled exception at 0x00401189 in ControlFileChanges.exe: 0xC0000005: Access violation writing location 0xbaadf00d at the first strcpy command.
char** withStrings(string s1, string s2, string s3, string s4, string s5)
{
char** pipes;
pipes = (char**) malloc(sizeof(*pipes)*5);
strcpy(pipes[0],s1.c_str());
strcpy(pipes[1],s2.c_str());
strcpy(pipes[2],s3.c_str());
strcpy(pipes[3],s4.c_str());
strcpy(pipes[4],s5.c_str());
return pipes;
}
Any idea what the problem could be?
(This is a sample that I am using to use similar logic in my actual code).
You didn’t allocate memory to
pipes[0],pipes[1], etc.Since this is C++ and not C, did you consider using
newinstead ofmalloc? Or maybe use avectororstrings ?