0
我想编译这个源代码:如何使用C11语言方言编译Xcode C文件?
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
int main(int argc, const char *argv[]) {
While:
printf("MacBook-Pro-...:~ ...$ ");
char command[128];
gets_s(command);
if (strncmp(command, "exit", 4) == 0)
exit(0);
pid_t return_value = fork();
if (return_value == 0) {
int outfile;
if ((outfile = dup(1)) == -1)
return -1;
close(1);
if ((outfile = open("/Users/.../1.txt",
O_WRONLY | O_TRUNC | O_CREAT, 0644)) >= 0) {
execl("/bin/sh", "sh", "-c", command, NULL);
}
close(outfile);
exit(0);
} else {
wait();
FILE *fp;
char str[128];
fp = fopen("/Users/.../1.txt", "r");
while(!feof(fp)) {
if(fgets(str, 126, fp))
printf("%s", str);
}
fclose(fp);
goto While;
}
return 0;
}
但我有一些错误: 语义问题
- 功能“gets_s”的隐式声明是在C99
- 隐式声明的库函数无效类型为'void(int)attribute((noreturn))'
- 函数'wait'的隐式声明在C99中无效
- 太少参数的函数调用,预计1,有0
系统:
产品名称:Mac OS X的 的ProductVersion:10.12.1 BuildVersion:16B2555
Xcode版本8.0(8A218a)
苹果LLVM版本8.0.0(铛-800.0.38) 目标:x86_64的 - 苹果darwin16.1.0 线程模型:POSIX