ios-(2) First C language Program (understanding compile, connect, run)

Source: Internet
Author: User

First, the choice of development tools

1, can be used to write code tools: Notepad, ULtraEdit, Vim, Xcode and so on.

2, choose the reason for Xcode: Apple official to provide the development of a weapon, simplifying the development of the project, has highlighted the function.

3. Use Xcode to create a new C program source code file (. C or. c extension)

# Develop Xcode

# New File

# Select a file type. C

Second, code writing

1. Program Structure

* Structure of C program: composed of functions

# Any C programming city has one or more program segments (small programs), each of which has its own function, which we generally call "functions". So, you can say that the C language program is composed of functions.

* Concept of function

# function Name: A program consists of countless functions, each with its own name.

# call (Execute) function: According to the function of the wine can call the corresponding function, perform the corresponding function.

* Entrance to program C

# The entrance to the C program is a function called Main, referred to as the main function.

# Regardless of the number of functions in the program, the main function is executed first.

2. Programming Program

* Write the main function (curly braces {} The content is the function body)

#include <stdio.h>

int main ()

{

printf ("This is the function body"); Output string Call system function

return 0;

}

Third, compile

1, what is compiled: C source program translated into the calculation can be identified 0 and 1

2. What compiler to use: Xcode3 is using the LLVM compiler with GCC,XCODE4 (front clang)

3. What if I use clang to compile the program?

* Enter in Terminal: Cc-c file name. C. (CD into the current directory)

* Compile successfully, generate. o target file.

4. Compiler Error and warning function

* If you have a problem with grammar, the compiler will report a direct error and indicate the number of errors and the exact line number.

* As long as there are 1 errors, the program will not compile successfully, it is not good to generate. o files.

* The warning message is just a compilation of some recommendations that do not affect compilation through.

Iv. Connection

1, the role of the connection: the. o file and the C language function library together to generate the executable file

2, the connector is completed, the Clang compiler contains the connection instructions.

* Terminal input: CC file. O.

* The connection is successful and the a.out executable is generated.

Five, the operation

1, two modes of operation

* Directly double-click Open a.out file.

* Use the./a.out directive in the terminal.

2, after modifying the contents of the file, be sure to recompile, connect, and then run.

3, \ n The role: carriage return line.

Vi. other clang directives

1, Liu Change the executable file name: CC xx.o-o filename

2, compile together, connect: CC XXX.C

Vii. Common Mistakes of beginners

1, do not write a semicolon, using a Chinese semicolon

2, string less double quotation marks, or use single quotation marks, double quotation marks inside double quotation marks

3, the code is not written inside the main function, before return

4. file extension is not. C or. C, e.g.. txt

5, compile the file with absolute path, note the place where the target file is generated.

Viii. Summary

1, the whole process of operation

* Code-to-run (C-language function library), compiler-, source code

2. Summarize the extension of common Files

*. c is a C language source file that is created when writing code

*. O is the target file, which is generated when the compilation is successful.

*. Out is an executable file that is generated when the connection is successful.

3. Summary clang directive

* Compile: Cc-c xx.c

* Connection: CC XXX.O

* Compile, connect: CC XXX.C

* Run executable file:./a.out

* Change the name of the executable file: cc xxx.o-o XXX

4. What errors will be encountered in development? If resolved?

* syntax error, can be resolved by the compiler errors information

* Logic error, need inner debug program

5. Learning Suggestions

* Learning programming is not learning English

* Readability of the program (very important)

* Beginners should not be too root to ask the bottom

Ix. examples

1. Output the following pattern in two different code ways

************

8888****

************

 

#include <stdio.h>

int Main ()

{

printf ("************\****8888****\************\ n");

return 0;

}

#include <stdio.h>

int Main ()

{

printf ("************\ n");

printf ("****8888****\ n");

printf ("************\ n");

return 0;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.