【发布时间】:2012-07-31 07:17:17
【问题描述】:
这段代码给了我运行时异常:Unhandled exception at 0x00401189 in ControlFileChanges.exe: 0xC0000005: Access violation writing location 0xbaadf00d at first strcpy 命令。
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;
}
知道问题可能是什么吗? (这是我在实际代码中使用类似逻辑的示例)。
【问题讨论】:
-
这是疯狂的代码,即使它没有错。它绝对不是“C++”。