C Language < The year before last note finishing > (a) C language first knowledge

Source: Internet
Author: User
Tags clear screen

Some instructions: Since this cock is an iso-born, so I learn the C language mostly in the MAC system to knock code.

(i)

Let's start with a few things about Mac.

========================================
One, Mac system use
1.mac System Brief Introduction
Mac is a Unix-like graphical interface operating system with two development environments: graphical IDE and terminal terminal. ( in short, Apple developed a set of operating systems )

2.Dock (docking bar-usually at the bottom of the screen), Finder (My Computer), common software (Safari, System Preferences)

3. File system
1) My Computer in Windows--equivalent to a finder in Mac

2) file path comparison
Windows d:/shipin/will be a no-no after. mp4
mac/users/mac/shipin/x. mp4 '/' represents the root directory


4. Common shortcut keys

A) Command+tab: switch applications under any circumstances

b) command+~: Switching between multiple windows of the same application

c) command+f: Call out the query function of most applications

d) command+c/v/x: Copy/paste/Cut

e) Command+n: New application window

f) Command+q: Exiting the current application

g) Control+space: Call out Spotlight, top right corner of the query icon.

h) Command+space: Toggle Input Method


========================================
Second, common terminal commands
How to open a terminal
1.---terminal by tapping the finder---application---utility
2. Will be pinned to the dock
Terminal Introduction
Host Name: current directory user name

Example: admindemacbook-pro:~ admin$

Unix commands
1.pwd Displays current directory, current working path
root directory and home directory
(a) root directory:
MAC system does not have the concept of partitioning , the entire computer file system from the root directory '/' Start from a layer of directories (Windows folder), files are installed in different directories according to the function. The entire system directory structure starts with the root directory '/' and forms an inverted tree structure .

(b) Home directory:
Each Mac user has a home directory , and all of the user's actions, such as the creation of a personal directory and files, are usually placed in that directory. Usually when Terminal Terminal is opened, it automatically enters the home directory of the current user.

2.ls file Display
1) Display the files in the current directory via LS

3.ls parameter usage
1) Display the information of the file in the current directory
ls-l //List
2) How to display all files, including files that begin with a point
Ls-a
3) How to display the specified directory file
ls [parameter] file name
4.CD Entry directory
1) How to access the catalogue
2) return to parent directory
3) Quick return CD to user directory

5. relative path and absolute path
(a) absolute path absolute path is the path of a file/folder that is computed from the root directory '/' .
Directory features at all levels of the work directory
/user/qianfeng/public
(b) Relative path relative path is the path of a file/folder of a computer starting from the current path .
Shenzhen-Zhangmutou-changping-Dongguan-Guangzhou

(c) The working directory where the current user of the current directory performs the action, the current directory can be changed by the CD command, and the PWD command displays the absolute path to the current directory. The current directory can be used with the identifier '. ' Reference.
1) How to access the directory by absolute Path
2) How to enter/catalogue

(d) In the parent directory root directory '/', each directory has a parent directory, which is often referred to as an ancestor directory. The parent directory can be used with the identifier '.. ' Reference.

Cd. Current directory
Cd.. Return to the upper level
CD-Last time
CD ~ Home


6. Directory Operations: Directory creation, replication, and deletion
1>.mkdir//Create File
2>.rm-r//deleting files or directories
3>.cp-r//Copy files or directories
4>.MV//operation in different directories is cut in the same directory operation is renamed

7 file operations: file creation , deletion, and replication
1>. Touch Create File
Touch file name

Files with duplicate names will never happen.

Open filename // Opening file (clip )

2>.rm
3>.CP replication
CP Source File Destination Path
4>.MV Cut
MV Source File Destination Path
Rename:
MV file name./New file name

Description: The command is actually some already written application
In addition to the terminal's own, there are third-party commands


Terminal Tips
1>. completion of file and command names
TAB key Completion
2>: Historical Command
Up and down search for arrow keys
History
3>. Clear Clear Screen or control+l

====================================

Two C Language Program writing

====================================

One, the first C program Hello World (Environment: Xcode and terminal)

 #include <stdio.h> //  contains header files int  Main (void ) //  {//  //  function body: function code   printf (  hello world\n   " );  return  0  ;}  //  main function End   output: Hello world  

Steps:

1. Write A. C source file (for example, I wrote a source file: ab.c )

2. Compile the. C source file into an. o target file ( cc-c ab.c )

3. Link ( cc ab.o ) to generate an executable file

4. Run./a.out

(Compile link together,cc AB.C )

II. development process of C program

1. Write A. c source file in Xcode

C programs consist of functions the entrance to the C program is the main function, only one , and there must be a

2. Compile the. C source file with clang. O Destination File

During the compilation process, the syntax of the program is detected, and the corresponding errors (error) and warning (warning) information is generated if there is an error (error), then the compilation fails and cannot be generated. o The target file if there is a warning (warning), does not affect the compilation, The. o target file can be generated (provided there is no error) the compilation process only detects syntax and does not detect the definition of a function

3. Use the clang link. o The destination file is an. Out executable file

Link will detect when there is no definition of the function, if not defined, the link fails

4. Run the. Out executable file with the terminal


compile : only the syntax is detected and no main function or other function is detected
link : the link will be strictly detected when there is no definition of the function (linker linker)

Note :

1) undefined Mark

Undefined Symbols for Architecture x86_64:
"_main", referenced from:
Error description: Because there is no main function
2) Compile the. c file that contains the blanks with the TAB key completion
3) The files generated at the terminal are in the current directory of the terminal

C Language < The year before last note finishing > (a) C language first knowledge

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.