I am trying to use the latest Xcode to simulate some C code, that has nothing to do with iPhone, only test some data manipulation on C functions, and print results to see it working.
我正在尝试使用最新的Xcode来模拟一些与iPhone无关的C代码,只测试C函数上的一些数据操作,并打印结果以查看它是否正常工作。
I have started a new playground in Xcode , for iOS , but it gives error when you try to write some C code ( char me[]= "this is me" ;
)
我已经在Xcode中开始了一个适用于iOS的新游乐场,但是当你尝试编写一些C代码时它会出错(char me [] =“这就是我”;)
How can i do it anyway ? thanks.
我怎么能这样做呢?谢谢。
1 个解决方案
#1
2
The playground is for swift, not C, hence the errors.
操场是快速的,而不是C,因此错误。
You can develop C programs using Xcode, but you want to target OSX, probably using the command line project template.
您可以使用Xcode开发C程序,但是您希望使用命令行项目模板来定位OSX。
Start by writing main()
:
首先编写main():
#include <stdio.h>
int main(int argc, const char **argv)
{
printf("Hello world!\n");
return 0;
}
EDIT: In order to call a function outside of main()
you must declare it before it is referenced:
编辑:为了调用main()之外的函数,必须在引用之前声明它:
// Forward declaration of function
static void printit(const char *message);
int main(int argc, const char **argv)
{
printit("Hello World\n");
return 0;
}
static void printit(const char *message)
{
fwrite(message, 1, strlen(message), stdout);
}
#1
2
The playground is for swift, not C, hence the errors.
操场是快速的,而不是C,因此错误。
You can develop C programs using Xcode, but you want to target OSX, probably using the command line project template.
您可以使用Xcode开发C程序,但是您希望使用命令行项目模板来定位OSX。
Start by writing main()
:
首先编写main():
#include <stdio.h>
int main(int argc, const char **argv)
{
printf("Hello world!\n");
return 0;
}
EDIT: In order to call a function outside of main()
you must declare it before it is referenced:
编辑:为了调用main()之外的函数,必须在引用之前声明它:
// Forward declaration of function
static void printit(const char *message);
int main(int argc, const char **argv)
{
printit("Hello World\n");
return 0;
}
static void printit(const char *message)
{
fwrite(message, 1, strlen(message), stdout);
}