simple loop error in objC
Hello I have a loop and开发者_开发问答 I have issues when int11=21 and when i=7.
-(NSString *)print01:(int)int11{
int n =128;
char array12[7];
NSString *str;
if(int11==0)
return str= [NSString stringWithFormat:@"00000000"];
for(int j=0;j<8;j++)
if ((int11-n)>=0){
//When i=7 then int11=1 and n=1, the "i" here is 7
array12[j]='1';
//and here is become 49!!!
int11-=n;
}
else
array12[j]='0';
n=n/2;
NSLog(@"Last %d",j);
}
str= [NSString stringWithFormat:@"%s",array12];
return str;
}
char array12[7];
and for(int j=0;j<8;j++)
and array12[j]='1';
induce an out-of-bounds problem.
精彩评论