您好 我有一个循环,当int11 = 21和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;
}
答案 0 :(得分:4)
char array12[7];
和for(int j=0;j<8;j++)
以及array12[j]='1';
会导致越界问题。