C Language Learning Guide for Unix and Linux

Source: Internet
Author: User
C Language Learning Guide for Unix and Linux-general Linux technology-Linux programming and kernel information. For details, refer to the following section. Introduction

Although C language has been around for nearly 30 years, its charm has not diminished. C language continues to attract a large number of developers who must learn new skills to write, transplant, or maintain applications.

This article is intended to meet the needs of C language beginners or developers who want to improve their C language skills. I hope it will be helpful for your study and work. You may not agree with some of these methods, but we hope you will like them.

This article does not describe how a programmer can understand the language details, but shares his learning experience on C Programming in UNIX with beginners. It does not describe the computer knowledge that a qualified programmer should possess, for example, operating systems, data structures and algorithms, and databases.

For whatever purpose you may wish to leave your criticism or suggestions after reading this article. Your pertinent criticism will become the motivation for the author to move forward.

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 to install the Virtual System Through VMware.

(2) Compilation tools

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.

Make tools such as 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" Later) and execute various operations to compile the program.

(3) 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 the program. Of course, you must learn how to use these tools, such as dbx, gdb.

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

(4) 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: http://vcd.gro.clinux.org/

2. netterm

One of the most famous network terminal software, you can use it to easily connect to the host system.

3. Secure shell

A client tool that supports ssh protocol is usually used to connect to a linux system.

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.

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 buy related books, these books will generally detail each function user and some points of attention; of course you can also log on to the http://www.dinkumware.com/manual ...... Amp?page=index.html to obtain the ansi c library details.

3. Overcome C's difficulties

C language statement:

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.

Array and pointer:

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.

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.

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.

Http://c-faq-chn.sourceforge.net/

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.

Method

Programming is a very practical job. The best way to learn is to debug the Code while reading the book, and repeatedly modify and debug the example programs in the book to get your own experience. Some test programs written in your own learning or work should be stored in different categories and constantly organized in future practical work. It is a good resource pool over time.

Sometimes, you may think that the examples in the book are easy to understand, but the practical value is not high. So to improve your programming capabilities, you also need to learn other people's code. I think studying others' code is the best and fastest way to improve your actual programming ability, now there are a lot of valuable open-source code on the network for you to choose to learn.

Finally, we have to mention that we should never overwhelm ourselves in the ocean of various technical details, such as the prefix ++ operator and expression computing priority.

Learning C Programming in UNIX or other programming languages, our final goal is to use computers to solve real-world problems, so we have accumulated solutions to common problems in daily work, and form a certain paradigm. refining is the most important thing. In the end, what design and programming do is methodology. Whether you are unconscious or conscious, you must pay attention to accumulation.

Additional instructions

1. if someone asks whether an ANSI C99 standard is required, it is not necessary for general developers, not to mention that the language is obscure, even if you can learn it from start to end, I want to improve your programming.

2. at present, most compilers such as cc and gcc in UNIX operating systems do not seem to support all the new features of C99. However, many new features are currently available, therefore, there is a reason to start seriously considering the adoption of the C99 feature in new development, especially where they are used to change the efficiency or clarity in essence (such as replacing macro with inner functions ).

3. programming specifications: Generally, more formal software companies will have their own set of completed programming specifications, so you can follow them. If you are learning by yourself, you can choose a more general specification. The best way is to see how others write code.

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.