How to Learn C language in UNIX/Linux, unixlinux

Source: Internet
Author: User

How to Learn C language in UNIX/Linux, unixlinux

I. Tools

"To do good deeds, you must first sharpen your tools ". Programming is a very practical job. In your future studies or work, you will often deal with the following tools. The following lists the software and tools that are often used to learn C programming.

1. Operating System

It is easy to learn C in UNIX or Linux systems. Therefore, before you start your learning journey, select a UNIX or Linux operating system, currently, free UNIX or Linux systems for individuals include FreeBSD, RedHat Linux, SUSE Linux, and many other practical tools, such as gcc and make, are provided in the installation package.

If you have been using Windows and there are no additional machines around to install UNIX, you can use VMware or Vbox to install the virtual system.

2,Compilation tool

At present, most Unix or Lnux systems provide CC or GCC compilers. The simplest cc command format is as follows:

Cc-o hello. c

In the unix shell environment, the above Code will compile the hello. c program into the executable file hello.

3. make Tool

For example, GNU make, System V make, and Berkeley make are basic tools used to organize the compilation process of applications. However, each make tool is different.

Most UNIX and Linux programs are compiled by running make.

The make tool will read a file containing commands (the name of this file is usually makefile or Makefile, but we call it "makefile" in this article) and execute various operations to compile the program.

4. debugging tools

The simplest debugging tool: Add print statements for your program. After you have a certain understanding of the program running mechanism, you can use some tools to help you debug your program, of course, you must learn how to use these tools, such as dbx and gdb.

Some memory tools can help you find problems such as memory leakage or buffer overflow, such as memwatch and yamd.

5. Other Tools

1) vi or vim

Unix text editor. It mainly relies on a bunch of commands to edit text files. It is best to be familiar with Unix programming and be proficient in using the vi editor.

Of course, in practice, you may need an integrated coding environment or a powerful graphical editing tool.

Provide a Chinese vim online manual:

2) Secure shell/putty
A client tool that supports ssh protocol is usually used to connect to a linux system.

Ii. Books


"Books are the ladder of human progress ". To learn a new knowledge, you must select a few books that suit your needs. The following describes some books that I have used to learn C language:

1. C primer plus
Recommended reason: it is suitable for beginners and basic function query reference. The latest version of this book is the fifth edition. The C language is detailed Based on ANSI C99.

2. The C programming_Language
Recommendation reason: There is no doubt that the work of the father of C language is authoritative. Although books have been published for a long time and seem to have not been updated, they are still classic books. On the Internet, this book must be downloaded in an electronic English version.

3. C expert Programming
Recommendation reason: this book can help experienced C programmers become C Programming experts. The most important thing is that this book is entertaining, so that you can fully enjoy programming.

4. C defects and traps
Recommendation reason: The knowledge revealed in the book can help you bypass the traps and defects of the C language itself and reduce many common bugs in the code.

5. Advanced Programming in unix environment

Recommended reason: Since it is C Programming in UNIX environment, you have to talk about UNIX programming books.

I strongly recommend Mr. Stevens's "Advanced Programming for unix environments", which is also a must for my case (if you are interested in network programming, you can take a look at Mr. Stevens's "UNIX network programming". If you think it is not good, you can look at "TCP/IP details ).

6. Computer Programming Art
Recommended reason: the algorithm master has to make painstaking efforts. Five-volume books are planned to be published. At present, it seems that three books have been published. If you are interested in algorithms, you can study them.

Iii. Process


1. Learn C syntax

Grammar learning is easy for a programmer. Even if you have never studied other programming languages before, I believe you can do it for 2 weeks.

Note that you should not be too entangled in the details of the language, such as the operator priority and associativity.

2. Learn the C Standard Library

The ansi c library divides functions into different groups. Each group has header files. Compared with other languages such as C ++, the C standard library is very short and concise in Java. However, you should first focus on the following libraries:

Ctype. h: Character Processing

Math. h: math

Stdio. h: Standard I/O Library

Stdlib. h: common tool Library

String. h: string processing

Time. h: time and date

If you want to know the complete ansi c library, you can purchase related books. These books generally detail the users of each function and some notes.

3. Overcome C's difficulties

1) C language declaration:
The C language statements make me feel terrible and obscure, and the declaration form and use form are similar. For example, the following statement may not be visible to many programmers who have been familiar with C for many years:
Char * const * (* next )();
Is there a good way or rule to figure it out? It seems that there is no such thing. If so, it is not like this. However, you may find some gains by taking a look at Chapter 3 of Expert C programming.
You can only learn more and practice more. The so-called practice makes perfect. I hope this problem will not be left in the shadows of your mind.

2) arrays and pointers:

The relationship between arrays and pointers is not detailed in the standards, and many C-entry books have not provided detailed descriptions on this issue, this may cause many misunderstandings.

For this question, you can refer to section 4.5 of C defects and traps and chapter 4, 9 and 10 of C expert programming, this issue will not be confused in the future.

3) pointer and memory:

If you write a large program in the future, you may find that this problem may be your biggest headache and may be the most time-consuming debugging.

4) C version problems:

You have to be very careful about this problem. It is best not to mix the features of different versions of C in your program, otherwise it will bring you a very confusing problem. If you must use it, you 'd better know what you are doing.

There are also some other difficulties and errors in C, so you can learn from the experience of our predecessors. The following is a link to the c FAQ. I believe you can solve most of the problems you need in this document.


4. Programming in UNIX environment

After learning the above content, I believe that you can program the unix environment. However, you may need to have a little understanding of the operating system theory, which makes it easier to learn.

For programming in the Unix environment, you should focus on IO and process.

The advanced programming of Unix environment has a very detailed and in-depth discussion of Unix environment programming. In addition, there are a lot of practical example programs in the book, but it may take a few months to get it done.
A solid grasp of the above content does not mean that you have completed the C language learning branch. On the contrary, it was just the beginning. In the future, you will need to use the learned knowledge to solve a large number of different practical problems. In the continuous practice process, you will gradually deepen your understanding of C. With the above foundation, you will find that you can quickly master other knowledge you need in practice.

What is the relationship between Unix/Linux and C language?

Both are written in c and c ++.
What is the relationship between Unix/Linux and C language?

Both are written in c and c ++.

Related Article

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: 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.