我首先将 buf 传递给数组是 schArray[i][0] = buf;
例如我需要 buf
进入schArray
ABCDEFG to [0][0]
1234567 to [1][0]
但我不能做这个结果
我的结果第二行替换第一行
Time 1: [0][0] = ABCDEFG
[1][0] = null
Time 2 :[0][0] = 1234567
[1][0] = 1234567
替换 [0][0]
char ***schArray;
int q,k;
schArray = (char***)malloc(sizeof(char*)*1000);
for(q = 0; q < 1000; q++){
schArray[q] = (char**)malloc(sizeof(char)*100);
for(k = 0; k < 1000; k++){
schArray[q][k] = (char*)malloc(sizeof(char)*100);
}
}
while(strncmp(buf, KEYWORD_endP,KEYWORD_PS_SZ)!=0){
schArray[commandnum][0] = buf;
printf("%s\n",schArray[0][0]);
printf("%s\n",schArray[1][0]);
printf("%s\n",schArray[2][0]);
val=printCommand(buf);
printf("child: %d\n",val);
// printf("child:%d",val);
memset(buf, 0, 80);
write(cTop[i][1],&buf,80*sizeof(char));
read(pToc[i][0],&buf,80*sizeof(char));
commandnum++;
}
预期产出
ABCDEFG
1234567
实际输出
1234567
1234567