练习题:
#import
intmain(intargc,constchar* argv[]) {
@autoreleasepool{
//定义一个block,block的功能传入一个字符串并计算字符串的长度,c里面的字符串是以\0来结束
int(^lengthOfStr)(charstring[]) =
^(charstring[]){
intcount =0;
charc = string[count];
while(c !='\0') {
count++;
c = string[count];
}
returncount;
};
charstr[1000];
printf("请输入字符串:\n");
scanf("%s",str);
intlength = lengthOfStr(str);
NSLog(@"%d",length);
}
}