have been using Xcode to learn Oc,swift recently. and develop iOS apps. Idle to dull, want to write a few C programs on the Mac. Once in Windows, we used Vc++,visual Studio, and so on C or C + + IDE. But what environment should we use to learn C when we come to the Mac? The answer is, of course, Xcode.
Xcode currently supports Swift in the language. Objective-c,c. Four kinds of C + +. Let's use Xcode to write a HelloWorld.
The detailed implementation process is as follows:
(1) Install command line Tool on Mac, if not installed please refer to my blog "Xcode command line Tools installation Method".
(2) Open Xcode, select "Create a new Xcode project", then in OS X, select Application below, and on the right side select "Command line Tool", for example to see:
。
(2) then enter the project name, select C in the following language, of course, there are several other languages to choose: Finally select the workspace, create it.
。
(3) After the project has been created. folder structure such as the following: we are very familiar with the. c File:
。
(4) Open main.c, can see very familiar C language code, the system has voluntarily generated a part of the code. Contains the output Hello world.
#include <stdio.h>int main (int argc, const char * argv[]) { //Insert code here ... printf ("Hello, world!\n"); return 0;}
The output results are as follows:
。
Summarize. Go through the above steps. Hello World, written in C in the context of Xcode, is done. Code it out for yourself.
Let me briefly explain the function result status return code. For the return value of a function, I am able to use some predefined constants such as the following:
#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define infeasible-1#define OVERFLOW-2
GitHub home: https://github.com/chenyufeng1991.
Welcome to visit us!
Using Xcode to implement the first C language program--hello World