- Selection of development tools
- Tools you can use to write code: Notepad, UltraEdit, Vim,Xcode , etc.
- Reasons to choose Xcode: Apple's official development tool, simplified development process, highlighted features
- Use Xcode to create a new source code file for a C program (extension. C or. c)
- Enter a file name and a directory to select files for
- Delete all automatically generated content from the file, starting from zero
- Code writing
- Program Structure
- The structure of the C program: consists of functions
- Any C language program is composed of 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 made up of functions
- Basic concepts of functions
- Function name: an infinite number of functions in a program, each with its own name
- Call (Execute) function: According to the function name can call the corresponding function, perform the corresponding function
- The entrance to the C program
- 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
- Writing Programs
- Write the main function (the contents of the curly braces {} are the body of the function)
int Main ()
{
return 0;
}
- write multiple functions , and make calls
int Test ()
{
return 0;
}
int Main ()
{
Test ();
return 0;
}
- Use the printf function to output content to the screen
#include <stdio.h>
int Main ()
{
printf ("Hello world!" );
return 0;
}
- Compile
- What is compiling: Translating C source programs into 0 and 1 that the computer can recognize
- What compiler to use: Xcode3 using GCC,XCODE4 with LLVM compiler (front end with clang)
- How do I compile a program using the Clang compiler?
- In the terminal, enter: Cc–c file name. C
- The compilation succeeds and the. O target file is generated
- Compiler Error and warning features
- If the code has a syntax problem, the compiler will direct an 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 and will not generate an. o file
- Warning messages are just some of the compiler's recommendations and do not affect compilation through
- Link
- What the link does: combine the. o file and the C-language function library to generate the executable file
- done by the linker, the Clang compiler already contains the link directive
- In the terminal, enter: CC file name. O
- Link succeeds, generates a.out executable file
- Run
- Two modes of operation
- Directly double-click Open a.out File
- Use the./a.out directive in the terminal
- After modifying the contents of the file, be sure to recompile, link, and then run
- \ n Function: Carriage return to newline
- Other clang instructions
- Modify executable file name: CC xxx.o-o filename
- Compile together, Link: cc xxx.c
- Common Mistakes for beginners
- Do not write semicolons, use a Chinese semicolon
- string with double quotation marks, or single quotes, double quotation marks inside.
- The code is not written inside the main function, before the return
- File extension is not. C or. c, e.g.. txt
- Compile the file with absolute path, note where the target file is generated
- Summarize
- The process of running the whole program
- Summarize the extension of common Files
- . c is a C language source file that is created when you write code
- . O is the target file that is generated when the compilation is successful
- . Out is an executable file that is generated when the link succeeds
- Summary clang directive
- Compilation: Cc–c xxx.c
- Link: cc XXX.O
- Compile, Link: cc xxx.c
- Run the executable file:./a.out
- What errors are encountered in development? How to solve?
- Syntax error, can be resolved by compiler errors
- Logic error, need to be patient to debug program
- Learning Advice
- Learning to program is not learning English
- Readability of the program
- Beginners should not be too root to ask the bottom
- Exercises
Output the following pattern in 2 different code types
************
* * Itcast * *
************
Content Source: Preach intelligence podcast Li Mingjie teacher Content
C language The first C language program and development tools