• Complain

Agus Kurniawan - Learning C By Example

Here you can read online Agus Kurniawan - Learning C By Example full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2015, publisher: PE Press, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Agus Kurniawan Learning C By Example
  • Book:
    Learning C By Example
  • Author:
  • Publisher:
    PE Press
  • Genre:
  • Year:
    2015
  • Rating:
    4 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 80
    • 1
    • 2
    • 3
    • 4
    • 5

Learning C By Example: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Learning C By Example" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

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.

Learning C By Example — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Learning C By Example" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Copyright

Learning C by Example

Agus Kurniawan

1st Edition, 2015

Copyright 2015 Agus Kurniawan

Table of Contents
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

1. Development Environment

This chapter explains how to start with development environment using C.

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.

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 122 Windows - photo 1

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.

After installed you will get Cygwin terminal Run it You can check GCC - photo 2

After installed, you will get Cygwin terminal. Run it.

You can check GCC version. The following is a sample of output for GCC version

123 Mac To install GCC you can install Xcode so you get GCC After - photo 3

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.

13 Development Tools Basically you can use any editor tool for instance - photo 4

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 14 Hello World Now we start to write the first - photo 5

Here is gedit editor

14 Hello World Now we start to write the first program using C Firstly open - photo 6

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 int main () { printf( "Hello C \n " ); return ;}

Save this file.

Now open your Terminal and compile this file.

sudo gcc hello.c

If you check you will get file aout GCC will generate aout file if you - photo 7

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

After compiled you can run the compiled file by writing this command for - photo 8

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 2 Basic C Programming - photo 9

A sample output of program is run on Mac platform.

2 Basic C Programming Language This chapter explains the basic of C - photo 10

2. Basic C Programming Language

This chapter explains the basic of C programming language.

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

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 = ;

You also declare as below

int myvar1;myvar1 = ;

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 int main () { int n; int i,j; n = "hello" ; return ;}

Save this code as file, called var1.c.

Try to compile this file. You will get a warning message as shown Figure as below

24 Comment You may explain how to work on your code with writing C To do it - photo 11

2.4 Comment

You may explain how to work on your code with writing C. To do it, you can use // and /* */ syntax. Here is sample code:

// bank account char accountCode; /* parameters*/ int p1, p2, p3, p4;

2.5 Input & Output on Console

You may want to show message on console using C. You can use printf() to write message on console. printf() also can be passed parameters inside using %d for integer numeric and %f for floating numeric. For char data type, we can use %c for passing parameter.

Here is a sample code

#include int main () { int n = ; float m = 1.245 ; char c = 'A' ; printf( "%d \n " ,n); printf( "%f \n " ,m); printf( "%.2f \n " ,m); printf( "%.3f \n " ,m); printf( "%c \n " ,c); return ;}

Save this code into a file, called inout.c.

Compile and run this code

You can see on f that wrote floating data with 6 decimal digits You can - photo 12

You can see on %f that wrote floating data with 6 decimal digits. You can specify the number of decimal digit by passing numeric after dot (.), for instance, %.2f and %.3f.

2.6 Arithmetic Operations

C supports the four basic arithmetic operations such as addition, subtraction, multiplication, and division. The following is the code illustration for basic arithmetic:

#include int main () { int a,b,c; a = ; b = ; c = a + b; printf( "%d + %d = %d \n " ,a,b,c); c = a - b; printf( "%d - %d = %d \n " ,a,b,c); c = a * b; printf( "%d * %d = %d \n " ,a,b,c); float d = a / b; printf( "%d / %d = %.2f \n " ,a,b,d); float e = ( float )a / b; printf( "%d / %d = %.2f \n " ,a,b,e); return ;}
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Learning C By Example»

Look at similar books to Learning C By Example. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Learning C By Example»

Discussion, reviews of the book Learning C By Example and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.