[AppleScript] 纯文本查看 复制代码 #import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//创建可变数组
NSMutableArray *arr = [NSMutableArray array];
//定义需要接受的字符串个数
int num = 2;
//循环
for (int i = 0; i < num; i++) {
//定义数组从控制台接收字符串
char ch[50];
NSLog(@"请输入字符串:");
rewind(stdin);
gets(ch);
//把C语言字符串拼接成OC字符串
NSString *str = [NSString stringWithFormat:@"%s",ch];
//把OC字符串放入数组中
[arr addObject:str];
}
//for增强遍历打印
for (NSString *str in arr) {
NSLog(@"%@",str);
}
//block遍历打印
[arr enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"%@",obj);
}];
}
return 0;
}
|