iphone - Objective-C , array initialization -


int num1, num2,num3,num4, i=0; nsmutablearray *chararray = [[nsmutablearray alloc] init];  while(num1 != 0 && num2 != 0) {   num3 = num1 & 1;   num4 = num2 & 1;   if(num3 != num4) {     if(num3 == 0) {       chararray[i++]= '0';       chararray[i++]= '1';       } else {       chararray[i++]='1';       chararray[i++]='0';        }   }   num1 = num1 > 1;   num2 = num2 > 1; } 

}

i kinda new objective-c, can tell me whats wrong this?

you can't use regular array-like subscripts nsarrays (and nsmutablearrays). add item, need call addobject method.. i.e. [chararray addobject:obj].

the other caveat can't add bare char nsarray, needs objective-c type. can use nsnumber class wrap it. code be:

[chararray addobject:[nsnumber numberwithchar:'0']]; [chararray addobject:[nsnumber numberwithchar:'1']]; 

but can still use regular c array , leave code unmodified, better solution in case. i.e.

char chararray[max_size]; 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -