正如caf在https://stackoverflow.com/a/1113041/1354779中谈到的那样,有一种方法可以在声明变量时使用初始化器来初始化已声明的数组。太好了,我现在想知道是否有一种方法可以一个一个地使用数组的每个项目。
我用它通过管道传递命令列表,我知道这有效:
char* script[]={"report blabla","report bla"};
char line[200];
char** command;
for (command = script ; **command ; **command ? command++ : 0){
if (**command){
SendCommand(*command, line, sizeof(line));
}
}
但是当我在下面尝试我的代码时,我得到一个“pipe_GWB9.exe 中 0x778915de 处的未处理异常:0xC0000005:访问冲突读取位置 0xcccccccc”:
char* request[] = {"report watact"};
char line[200];
// [...] Other code [...]
static const char *tmp[8] =
{
"report molality H+",
"report molality Cl-",
"report molality Ca++",
"report molality Mg++",
"report molality K+",
"report molality Fe++",
"report molality SO4--",
"report molality Na+"
};
memcpy(request, tmp, sizeof request);
char** command;
command=request;
SendCommand(*command, line, sizeof(line));
// Until here, everything works great.
**command ? command++ : 0;
SendCommand(*command, line, sizeof(line));
// But THAT doesn't work!!
您能帮我调用数组请求的其他项目吗?
谢谢