Copy the contents of a 1D array to another by value in C -


i'm trying copy value contents of dynamically-allocated array stillplaying tmpintarray long value isn't -1, ie tmpintarray should hold values in stillplaying, sans -1.

i error message subscripted value neither array nor pointer nor vector when attempting compile.

tmpintarray = (int*) malloc(nparticipantsleft*sizeof(int)); for(i = 0; < nparticipantsleft; i++) {   if (stillplaying[k] == -1)      k++;   tmpintarray[i] = stillplaying[k]; } 

thanks helping me out easy question.

declaration @ top of file:

int * stillplaying,  //points array of ids players not out       tmpintarray;   //holds intermediate version of stillplaying 

besides wrong declaration of tmpintarray should int *tmpintarray, think code should this:

int j = 0;  for(i = 0; < nparticipantsleft; i++) {     if (stillplaying[i] != -1) {         tmpintarray[j++] = stillplaying[i];     } } // j contains number of players in tmpintarray 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -