[C language exploration journey] Lesson 2: to do things well, you must first sharpen your tools.

Source: Internet
Author: User

[C language exploration journey] Lesson 2: to do things well, you must first sharpen your tools.




Introduction


1. Course outline

2. Part 1 Lesson 2: to do good deeds, you must first sharpen your skills.

3. Part 1 Lesson 3 Notice: Your first program



Course outline


Our courses are divided into four parts. Each part has exercise questions after completion and answers will be published. Three games will also be written in C language.



Basic knowledge of C Programming


  • What is programming?

  • To do their best, you must first sharpen your tools.

  • Your first program

  • World of Variables

  • Operator

  • Conditional expressions

  • Loop statement

  • Practice: The first C games

  • Function

  • Exercise questions

  • Exercise: Perfect the first C games



C Advanced Technology


  • Modular programming

  • Attack pointer, C trump card

  • Array

  • String

  • Preprocessing

  • Create your own variable type

  • File read/write

  • Dynamic Allocation

  • Practice: "hanging villain" games

  • Secure text input

  • Exercise questions

  • Exercise: Explain the pointer in your own language



Develop 2D games with C language-based SDL Library


  • Install SDL

  • Create a window and canvas

  • Show images

  • Event Processing

  • Practice: "Super Mary pushes boxes" games

  • Time usage

  • Use SDL_ttf to edit text

  • Use FMOD to control sound

  • Practice: Visual Sound line

  • Exercise questions



Data Structure


  • Linked List

  • Heap, stack, and queue

  • Hash table

  • Exercise questions



Part 1 Lesson 2: to do good deeds, you must first sharpen your skills.


Yesterday's class had a better response than I could have imagined. Excited and grateful.


Yesterday I said that programmers need to possess three characteristics:

Patience, logic, and calm.

I suddenly felt that I still needed the fourth biggest feature-modesty, which is very important. Because you will only find that the more you learn, the less you feel, the larger the world outside, the more advanced programmers and the greater the world, the new technologies will always emerge faster than you learn, so always keep a new heart.

I am grateful for everything. On the one hand, I am grateful to those who have helped us, those who have been loyal to us, and those who have accompanied us in the computer and open-source communities.


In fact, I always think that programmers are a good profession. Although programmers may have many occupational diseases, such as less talk, house, stay cute, and shy,

But programmers are relatively simple. This is inseparable from the computers we are accompanied. Because the machine won't say anything, 1 is 0, 0 is 0, absolutely loyal, efficient, and don't change your mind (core ). As a result, programmers who have been dealing with machines for a long time have become less confident and feel cute.


There was an article on the internet saying that it is interesting to ask programmers to be friends between men and women.

After getting along with several colleagues in the company, I also found that programmers are really interesting, cute, and childlike.


Programmers in China are not too valued, but I believe that with the strength of China, it will change.


Let's get down to the truth. After the last lesson "What is programming", we officially entered the C language programming topic.


In this lesson, we answer the following questions:

What software do we need to program?


You can spend this lesson easily, because there is no difficulty. We will spend some time learning some common programming software.

We should have a good time in this lesson, because we have to write a program at the beginning of the next lesson, so we should drink coffee, eat roast chicken, eat roast chicken, and have a good rest before we can get involved.


Essential programming tools


According to you, what software is necessary for programming? If you take the last lesson seriously, you can say at least one.


By the way, it is the compiler. This important program can convert your source code (instructions written in advanced languages such as C Language) into binary codes that computers can understand (only containing 0 and 1, like 01100110001111011101010 ...).

In the previous lesson, we also mentioned that each high-level language has a corresponding compiler (of course, there is no need to compile an interpreted language like Python). There are many compilers in C language alone. GCC (gnu c Compiler) is commonly used. GNU is an internationally renowned Free Software Foundation. GNU is the recursive abbreviation of "GNU is Not Unix" (GNU is Not Unix). Foreigners are always so naughty, like programming, for example, recursion of "Linux Is Not Unix" (Linux Is Not Unix. It is especially fun to use the names or icons of many animals ).


What tools do we need besides the compiler?

The following lists the basic programming tools:


  • Text Editor: a tool used to write source code. Theoretically, Windows OS notepad or Linux VI editor can be used as a text editor. However, it is better to use some more advanced text editors, such as supporting code highlighting to facilitate inter-code jump. Personally, the recommended text editor is Emacs, which is really strong, cross-platform (such as Apple Mac, Windows, and Linux), customizable, combinations of shortcut keys, sending and receiving emails, watching videos, and Browsing webpages, browsing PDF, you can't do it, just think of it (slightly exaggerated ...), this allows you to edit code very efficiently. I used VIM before and it was quite good. But I used Emacs later, and I still prefer Emacs. Of course, this is wise. There is also a text editor: Notepad ++ is also quite good. After configuring and installing some plug-ins, it can be very powerful, but it seems that there is no Apple computer version.


  • Compiler: it has already been mentioned to convert (or compile) your source code into binary code.


  • Debugger: Debugger, a tool used to track and discover errors in a program. Here is a new term called Debug ). Bug is an English bug. The bug means that de is a prefix in English that indicates "Separation and removal". So Debug means removing the bug. Generally, errors or defects in a program are called bugs, which are said to be due to the legend of female programmer Grace Hopper. hope) one time I found a moth in the MARK II computer, which was a very large computer in the early days, the moth caused the computer to crash (between the relays in the computer). Hope clipped the moth with tweezers and pasted it on his notebook with transparent adhesive tape, and indicate "the first instance for discovering bugs ". Since then, people have followed this title and used debug to indicate the behavior of eliminating program errors. Now Hope's notebook, along with the cute moth, is displayed in the American Museum of History.


Hope's notebook and glorious moth loaded into history


Of course, if you are adventurous and want to challenge yourself, you don't need a debugger (you can also find the error by yourself through some tips ). However, I think you usually need a debugger.


Therefore, we have two options:

  • Use the text editor, compiler, and debugger tools separately. Although complicated, it works. Especially in Linux, many programmers still like to program in this way. It may not be installation, but it is feel, which is cool.

  • Use a software that integrates the functions of these three tools. This kind of software is called Integrated Development Environment (IDE ).


In the beginning, it may be difficult for you to decide which one to use? Even if you choose to use IDE, you will also find out which IDE to use. In fact, we can be certain that no matter which tool you choose, you can write the program you want. It's just efficiency. personal habits are different from specific platform requirements.


For more information, see:

If you are new to C language, try to learn C language programming in the Linux Command Line. Do not use IDE at first. Because IDE is doing a great job, there are prompts, and the code is automatically supplemented to help you add code automatically, you can't learn much, but you can't remember it. When the programming level is better, it is not too late to use IDE. At that time, IDE can improve your programming efficiency. It is a good choice to use emacs or vim to compile C language, GCC to compile C language, and GDB (GNU Debugger) to debug C language.


Of course, we will spend a lot of time introducing several commonly used ides.


Select your IDE


We think it is necessary to show you several of the most famous ides, which are free of charge (only buy right, not choose expensive)


  • Code: Blocks: A favorite IDE, which is free, open-source, and cross-platform.In subsequent courses, we will use Code: Blocks for development.Because the Code: Blocks development environment is set up too quickly and does not require any configuration.

    It can run on Mac, Windows, Linux, and many other operating systems.


  • Visual Studio: the basic version is charged. Fortunately, a Visual Studio Express version is free of charge. The VS function is complete and the debugger is powerful.

    It can only run on Windows.


  • Xcode: as Apple's home IDE, I have to say that Xcode is really great. It can be used to develop basic small programs, iPhone and iPad apps (super fast simulator), smart watch apps, and other 3D engines such as Unity to compile games.

    It can only run on Apple Mac OS X.



Code: Blocks

Code: Blocks is a very good IDE, but currently only the English version is available. Of course, there are also Chinese versions on the Internet. However, since learning programming, I should try to turn off the English language, it does not need to be too good at English. After all, some translations of the Chinese version are not in place and may affect the usage. In addition, good programming resources are basically in English.


Download Code: Blocks

Go to Code: Blocks official download page: http://www.codeblocks.org/downloads/binaries

  • For Windows users, download the. exe file,Please note that you need to download the one with the mingw name(Codeblocks-13.12mingw-setup.exe), because it will be very troublesome if the versions without mingw do not contain the compiler.

  • For Linux users, download the version corresponding to your operating system

  • Apple Mac users download CodeBlocks-13.12-mac.zip



Install and run the Code: Blocks

Code: the installation of Blocks is too simple, it is no difference with the installation of QQ, it is good to default all the way to the end.

After the installation is complete, double-click to run it. You can see the interface shown in figure



Marked with four areas:

  1. Toolbar: There are many buttons, but there are only a few buttons that we often use.

  2. Project file list area: All files of your project are displayed in the left column.

  3. Main Interface: code writing place

  4. Notification bar: you will see running errors, compilation problems, and so on.


How to create a basic console application in C language?


First, go to the menu and choose File> New> Project. The following window is displayed:



As you can see, Code: Blocks supports many program types. These program types use different libraries, such as SDL (developing 2D programs), OpenGL (developing 3D programs ), qt and wxWidgets. Currently, many of these icons are just nice-looking, because you have not installed the corresponding library, and none of them can be used. We will develop games based on the SDL library in subsequent courses. For the moment, we only use the most basic Console application (the Console application, in simple words, will pop up a box showing the program running results ).


Select Console application and click Go to next step.



Enter the name of the Project you want to create in "Project Title". We enter the famous HelloWorld. "Folder to create project in" is the path for storing the selected project.

Click Next to Next,



Here we do not need to change anything, the default is good. Click Finish to complete the configuration. Code: Blocks will create your first project.



Open main. c: The c language source code file. Click a green triangle button in the toolbar above to run the program. It will prompt you whether to compile the program. Click "yes ", after running, our first console program outputs Hello World!



Visual Studio


Download Visual Studio Express, go to official download page http://www.visualstudio.com/products/visual-studio-express-vs

Select a version suitable for your operating system to download.

Because the editor edited the article on the Apple computer, I will not do more demonstration. Please refer to the installation and use of text tutorials on the Internet. Sorry.

After installation and running, the layout should be similar to Code: Blocks.




Xcode

There are many ides in Mac operating systems, but Xcode is a favorite of Apple users.

Not all Apple users are programmers, So Apple didn't pre-install Xcode in Mac systems. You need to download Xcode from Mac App Store (App Store) (you need an apple account, no one can be registered ).


It is easy to Install. You only need to search for Xcode in App Store and then click Install to Install it in the application. Run Xcode



Select Create a new Xcode project (Create a new Xcode project). The following window is displayed.



Choose OS X-> Application-> Command Line Tool and click Next to Next.



Enter the Project Name in the Project Name, And we enter HelloWorld. Select Language C and click Next. The path of the project folder will be selected. Click Finish.



After the project is opened, click the triangle button to run. The output is Hello World!



To sum up

  • A program needs to be compiled from the beginning to run. Generally, three tools are required: Text Editor, compiler, and debugger. (Of course, it does not need to be compiled for an interpreted language like Python)

  • We can use these three tools separately to complete the task. But it is more convenient to use IDE (integrated development environment, mixed with the three) for development.

  • Code: Blocks, Visual Studio (or Visual C ++), Xcode is the most famous IDE, and of course there are many excellent IDES (such as Eclipse. IDE is just a tool.



Part 1 Lesson 3 Notice: Your first program


Today's class is here. Come on together. In the next lesson, let's write our first C language program.





Programmer Alliance public account* If you think this article is good, click "share"

* New friends should follow the "Programmer alliance" Search Public AccountProgrammerleleague

Little Editor: frogoscar

Small mailbox: enmingx@gmail.com




The "Programmer alliance" public account is designed for programmers and App designers. You love programming and sharing to push a wide range of programming-related knowledge, excellent software recommendations, and industry trends. Search for ProgrammerLeague and follow-up ~


Continuous attentionProgrammer AlliancePublic Account, more interesting, expected, and content with highlights are waiting for you!


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