我试图按值将动态分配数组stillPlaying的内容复制到tmpIntArray,只要该值不是-1,即tmpIntArray应该包含stillPlaying中的所有值,而不包含-1
我在尝试编译时收到错误消息subscripted value is neither array nor pointer nor vector

tmpIntArray = (int*) malloc(nParticipantsLeft*sizeof(int));
for(i = 0; i < nParticipantsLeft; i++)
{
  if (stillPlaying[k] == -1)
     k++;
  tmpIntArray[i] = stillPlaying[k];
}

谢谢你帮我解决了这个问题。
文件顶部的声明:
int * stillPlaying,  //points to array of IDs for players who are not out
      tmpIntArray;   //holds the intermediate version of stillPlaying

最佳答案

除了tmpIntArray的错误声明应该是int *tmpIntArray,我认为代码本身应该是这样的:

int j = 0;

for(i = 0; i < nParticipantsLeft; i++)
{
    if (stillPlaying[i] != -1) {
        tmpIntArray[j++] = stillPlaying[i];
    }
}
// j contains number of players in tmpIntArray

10-04 15:26