【发布时间】:2016-03-21 11:25:29
【问题描述】:
我有一个命令行C game 的源代码,它等待用户的stdin,并输出stdout。我想将来自文本字段的输入提供给此C 代码的main,并以文本区域字段中的输出为例。
int mainer(int argc, char **argv) {
int i;
int hitme;
char ch;
prelim();
if (argc > 1) { // look for -f option
if (strcmp(argv[1], "-f")== 0) {
coordfixed = 1;
argc--;
argv++;
}
}
if (argc > 1) {
fromcommandline = 1;
line[0] = '\0';
while (--argc > 0) {
strcat(line, *(++argv));
strcat(line, " ");
}
}
else fromcommandline = 0;
// some other code
}
从示例here 中,我应该执行以下操作:
let args = [" ", "regular", "short", ""]
var cargs = args.map { strdup($0) }
let result = mainer(Int32(args.count), &cargs)
for ptr in cargs { free(ptr) }
我怎样才能调用main function,让它保持活力并不断给它参数以使其充当command line。
【问题讨论】:
标签: ios c swift command-line-interface