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