Learning C By Example (Agus Kurniawan) (z-library.sk, 1lib.sk, z-lib.sk)
Author: Agus Kurniawan
C/C++/C#
This book help you how to get started with C programming. This book provides many code samples for illustration. The following is highlight topics: * Development Environment * Basic C Programming Language * Array and Pointer * Functions * I/O Operations * String Operations * Building C Library * Threading * Database Programming * Socket Programming This book uses GNU GCC compiler for C programming.
📄 File Format:
PDF
💾 File Size:
4.0 MB
5
Views
0
Downloads
0.00
Total Donations
📄 Text Preview (First 20 pages)
ℹ️
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
📄 Page
1
(This page has no text content)
📄 Page
2
Copyright Learning C by Example Agus Kurniawan 1st Edition, 2015 Copyright © 2015 Agus Kurniawan
📄 Page
3
Table of Contents Copyright Preface 1. Development Environment 1.1 Getting Started 1.2 Compilers 1.2.1 Linux 1.2.2 Windows 1.2.3 Mac 1.3 Development Tools 1.4 Hello World 2. Basic C Programming Language 2.1 Common Rule 2.2 Declaring Variable 2.3 Assigning Variables 2.4 Comment 2.5 Input & Output on Console 2.6 Arithmetic Operations 2.7 Mathematical Functions 2.8 Comparison Operators 2.9 Logical Operators 2.10 Increment and Decrement 2.11 Decision 2.11.1 if..then 2.11.2 switch..case 2.12 Iterations 2.12.1 For 2.12.2 While 2.13 Struct 3. Array and Pointer
📄 Page
4
3.1 Array 3.1.1 Defining An Array 3.1.2 Basic Array Operations 3.2 Multidimensional Array 3.3 Pointer 3.3.1 Basic Pointer 3.3.2 Dynamic Array 4. Functions 4.1 Creating Function 4.2 Function with Parameters and Returning Value 4.3 Function with Array Parameters 4.4 Function and Pointer 5. I/O Operations 5.1 Getting Started 5.2 Reading Input from Keyboard 5.2.1 getchar() and putchar() functions 5.2.2 gets() and puts() functions 5.2.3 scanf() function 5.3 Reading Program Arguments 5.4 Writing Data Into A File 5.5 Reading Data From A File 6. String Operations 6.1 Concatenating Strings 6.2 String To Numeric 6.3 Numeric to String 6.4 String Parser 6.5 Check String Data Length 6.6 Copy Data 6.7 Exploring Characters 7. Building C Library 7.1 Getting Started
📄 Page
5
7.2 Writing C Library 7.3 Compiling and Testing 7.3.1 Static Library 7.3.2 Shared Library 8. Threading 8.1 Creating Thread 8.2 Thread ID 8.3 Terminating Thread 8.3.1 Terminating Itself 8.3.2 Terminating Others 8.4 Joining Thread 8.5 Thread Mutex 8.6 Condition Variables 8.6.1 Signaling 8.6.2 Broadcasting 9. Database Programming 9.1 Database Library for C 9.2 MySQL 9.3 Connection Test 9.4 CRUD (Create, Read, Update and Delete) Operations 9.4.1 Creating Data 9.4.2 Reading Data 9.4.3 Updating Data 9.4.4 Deleting Data 10. Socket Programming 10.1 Getting Local Hostname 10.2 Creating and Connecting 10.2.1 Server 10.2.2 Client 10.2.3 Testing 10.3 Data Transfer
📄 Page
6
10.3.1 Server 10.3.2 Client 10.3.3 Testing Contact and Source Code Contact
📄 Page
7
Preface This book is a practical book to get started with C language. It describes all the elements of the language and illustrates their use with code examples. Agus Kurniawan Depok, March 2015
📄 Page
8
1. Development Environment This chapter explains how to start with development environment using C.
📄 Page
9
1.1 Getting Started C is a general-purpose, imperative computer programming language. It supports structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. In this chapter, we prepare development environment to develop C program. You can write C program with your program. We focus on Windows, Linux and Mac platforms.
📄 Page
10
1.2 Compilers There are many C compilers to develop C program. In this book, we use GCC as C compiler for Linux, Mac and Windows. For Windows users, you also can use Visual C++ compiler. 1.2.1 Linux Installation of GCC C is easy. For Ubuntu Linux, you can do it using console and write this script $ sudo apt-get install build-essential If installation already finished, you can check GCC version on console and write script as below gcc --version You will see gcc version, for instance shown in Figure above. 1.2.2 Windows If your computer has Windows platform, you can use Cygwin. Download it on http://cygwin.com/setup.exe and then run it. On setup dialog, you choose Devel package as follows.
📄 Page
11
After installed, you will get Cygwin terminal. Run it. You can check GCC version. The following is a sample of output for GCC version 1.2.3 Mac To install GCC, you can install Xcode so you get GCC. After installed, you can verify it by checking GCC version.
📄 Page
12
(This page has no text content)
📄 Page
13
1.3 Development Tools Basically you can use any editor tool for instance, vi, vim, gedit, Eclipse. The following is vi editor in Ubuntu. Here is gedit editor
📄 Page
14
1.4 Hello World Now we start to write the first program using C. Firstly, open your text editor and create new file, called hello.c Let’s write this code #include <stdio.h> int main() { printf("Hello C\n"); return 0; } Save this file. Now open your Terminal and compile this file. sudo gcc hello.c If you check, you will get file a.out. GCC will generate a.out file if you don’t specify an output file name. You can define the output compiled file as follows sudo gcc hello.c -o hello
📄 Page
15
After compiled, you can run the compiled file by writing this command (for instance, the compiled file is hello.out) ./hello A sample output of program is run on Mac platform.
📄 Page
16
(This page has no text content)
📄 Page
17
2. Basic C Programming Language This chapter explains the basic of C programming language.
📄 Page
18
2.1 Common Rule In C language if you write a line of code we must write semicolon (;) at the end of code. Here is the syntax rule: syntax_code;
📄 Page
19
2.2 Declaring Variable To declare a variable called myvar1, write the following: int myvar1; int is data type. The following is the list of common data type you can use in C language. int long float char double We can also write many variables as follows: int myvar1, myvar2; Once declared, these variables can be used to store data based on its data type.
📄 Page
20
2.3 Assigning Variables Variable that you already declare can be assigned by a value. It can done using the equals sign (=). For example, variable myvar1 will assign the number 100, you would write this: int myvar1 = 100; You also declare as below int myvar1; myvar1 = 100; You must assign a value on a variable properly based on data type. If not, you will get error on compiling process, for instance, write this code #include <stdio.h> int main() { int n; int i,j; n="hello"; return 0; } Save this code as file, called var1.c. Try to compile this file. You will get a warning message as shown Figure as below
The above is a preview of the first 20 pages. Register to read the complete e-book.
Recommended for You
Loading recommended books...
Failed to load, please try again later