# #C Programming(I) - 1 ## Hello world English: Lei KuoLiang nicolaslouis@mail.fcu.edu.tw Chinese(TW): Wang M.H --- ## C language C language is a general-purpose programming language widely used in the development of system software and application software. It is highly efficient, flexible, feature-rich, expressive and portable, and is highly popular in programming. The design of C language has influenced many later programming languages, such as C\++, Objective-C, Java, C#, etc. (taken from the wiki) --- ## Compiler & Editor (IDE) ---- ### Compiler A compiler is a computer program that translates source code written in a high-level programming language (for example, C, Java...) into a low-level machine language that can be interpreted and executed by a computer, that is, an executable file. Compile ``` Original program → Via compiler → Become destination file → Via linker → Become executable file Source.c → COMPILER → source.o → LINKER → source.exe ``` ---- ### IDE If you want to use C language to develop software, you need to use C or C\++ compiler. (C\++ compiler includes C compiler) Compilers commonly used by students (integrated development environment/IDE): Dev-C\++, Code::Blocks, Visual Studio ---- Remember the program compilation process just now? ``` Compile Source.c --> COMPILER --> source.o --> LINKER --> source.exe 2. Execution > gcc source.c -o run.exe > ./run.exe ``` At this time, it is necessary to talk about the convenience of the IDE! Just click F9 (Build and run) ---- ### Dev-C++ ![](https://a.fsdn.com/allura/p/orwelldevcpp/icon?1480458710?&w=90) The school computer is built in. A set of free and open source C/C++ programming software, small size does not take up space, but development is not active. * [Carrying Point] (https://sourceforge.net/projects/orwelldevcpp/) * [Installation Teaching] (http://cbook.hackersir.org/Ch0/01_devcpp.html) ---- ### Code::Blocks ![](https://a.fsdn.com/allura/p/codeblocks/icon?1540580848?&w=90) A free, open source, cross-platform, integrated development environment, developed using C\++, designed primarily for developing C/C++ programs. * [Carrying Point] (http://www.codeblocks.org/downloads/binaries) * [Installation Teaching] (http://cbook.hackersir.org/Ch0/02_codeblocks.html) ---- ### Visual Studio ![](https://visualstudio.microsoft.com/wp-content/uploads/2019/04/BrandVisualStudioWin2019.png) Referred to as VS, it is a series of development tool kits from Microsoft Corporation. Visual Studio can support many programming language development software, such as: Visual C#, Visual J#, Visual Basic (VB), Visual C++ (including C compiler), Javascript, Python, etc., very powerful. * [Official website] (https://visualstudio.microsoft.com/) * [Installation Teaching] (http://cbook.hackersir.org/Ch0/03_visualstudio.html) --- ## First program Hello world ---- The code below allows the computer screen to output Hello world! ```c= #include <stdio.h> #include <stdlib.h> int main() { printf("Hello world!"); return 0; } ``` ---- Code description ```c= //Reference the header file, telling the compiler where the function used by the code comes from... #include <stdio.h> #include <stdlib.h> int main() //The main function, where the program execution begins { printf("Hello world!"); //Printf is a function used by C language to output return 0; //Backhaul, the value is returned at the end of the function, and the main function returns 0 for normal end. } ``` ---- ### Big parantheses { } & Semicolon ; ```c=4 int main() { printf("Hello world!"); return 0; } ``` The code enclosed in braces is a block of code. The semicolon represents the end of the narrative. In the C language, if there is no semicolon to directly wrap, the compiler will treat the next line as the next line, as the same statement (and then error). --- ### Exercise 1 Print out the text you want! ``` Hello World ------------------------------------- Process exited after 0.05654 seconds with return value 0 Please press any key to continue . . . ``` --- ## Make it easier to read programs Indentation & Annotation ---- ### Indent In C, indentation is to make the program look more structured In the code, the text enclosed by braces, indented 4 blank keys ![](https://i.imgur.com/CK517YK.png) ---- Indentation can help readers more easily see the structure of the code ```c= #include <stdio.h> #include <stdlib.h> int main() { printf("Indented is easy to read"); return 0; } ``` ```c= #include <stdio.h> #include <stdlib.h> int main() { printf("Not indented, not easy to read and ugly"); return 0; } ``` ---- Whether it is self-practice, homework, or exams, please develop a good indentation habit from now on! The future code is written to 50, 100 lines, or even thousands of lines. If you don't develop the indentation habit, no one dares to look at the of your code. XD ---- ### Comment Explain your code to the reader and the future ---- Single line annotation // ... Multi-line annotation /* ... */ ```c= /* 108th Year IECS 1A First week briefing */ #include <stdio.h>//Header file #include <stdlib.h> int main()//Main function { printf("Annotation at a glance");//Print out text return 0;//Return, end function } ``` ---- The text in the annotation does not affect the running of the program. Write programs to develop annotation habits and improve program readability --- ## How to change lines? ---- ### Challenge line break The beginning and end of double quotes " " must be on the same line of code The following is an error demonstration, there is no way to successfully compile ```c printf("I am the first line I am the second line"); ``` ---- ### usage of \\n \\n is a newline symbol, a type of skipping character The following code can correctly implement line breaks ```c printf("I am the first line\n I am the second line\n"); ``` ---- If you feel that two lines are crowded together, it is very uncomfortable. You can also write like this ```c printf("I am the first line\n" "I am the second line\n"); ``` Of course, you can also execute printf twice. ```c printf("I am the first line\n"); printf("I am the second line\n"); ``` ---- Note that if you don't use \\n, printf won't wrap automatically! If there is no special need, please get used to add \\n at the end. In order to output from the next line when the text is output next time. --- ### Exercise 2 Print out school, class, student number, name ``` School: Feng Chia University Class: IECS 2B Student ID: D777300ER Name: Victoria Mauricia ``` --- ## Skip character ---- Just now, we introduced the newline symbol \\n, which is a kind of skip character. The skip character is used to indicate some invisible characters or characters that are repeated with the C language symbols. ---- |Bounce character |Description|Bounce character|Description| |-|-|-|-| ==\t== |Horizontal positioning (tab)|\a |Humming ==\n== |Newline|\b |Rewind button ==\\"== |Show double quotes "|\r |Back to the beginning ==\\'== |Show single quotes '|\0 | end of string ==\\\\== |Show backslash \\|==%%== |Show percent sign % --- ### Exercise 3 Print out 3 lines of text including ++ double quotes ++ and ++ percent sign ++ ``` "107 school year information is male to female" Boys: 792, girls: 151 Female ratio: 16.0% ``` --- ## Homework ---- In the semester's homework, we will gradually create a "turn-based game". At the end of the freshman year, we will make a complete little game. ---- This week's homework content: Print out three characters of your own design with printf ``` Print out 3 self-designed characters and information (role name, attribute, blood volume, attack power, defense) Don't have duplicate role names or exactly the same information for both groups Attributes: F = fire, W = water, G = soil, A = wind Data limit: Blood volume 40~50 Attack 15~20 Defense 5~10 The sum of the three is between 65 and 70. ``` ---- Sample output ``` Role 1 Name: Han Dao Attribute: W Attack: 15 Blood volume: 50 Defense: 5 Role 2 Name: Yasna Attribute: A Attack: 20 Blood volume: 40 Defense: 8 Role 3 Name: Rem Attribute: F Attack: 17 Blood volume: 45 Defense: 7 ``` --- ###### tags: `108 Ai-Mod-Eng-LKL`
{"metaMigratedAt":"2023-06-15T01:36:48.136Z","metaMigratedFrom":"YAML","title":"W1 - Hello world","breaks":true,"slideOptions":"{\"transition\":\"slide\"}","contributors":"[{\"id\":\"befaa4d9-75b6-4c05-baa7-7949e0ffa1e2\",\"add\":13275,\"del\":4882}]"}
    256 views