Book Image

Learn C Programming

By : Jeff Szuhay
Book Image

Learn C Programming

By: Jeff Szuhay

Overview of this book

C is a powerful general-purpose programming language that is excellent for beginners to learn. This book will introduce you to computer programming and software development using C. If you're an experienced developer, this book will help you to become familiar with the C programming language. This C programming book takes you through basic programming concepts and shows you how to implement them in C. Throughout the book, you'll create and run programs that make use of one or more C concepts, such as program structure with functions, data types, and conditional statements. You'll also see how to use looping and iteration, arrays, pointers, and strings. As you make progress, you'll cover code documentation, testing and validation methods, basic input/output, and how to write complete programs in C. By the end of the book, you'll have developed basic programming skills in C, that you can apply to other programming languages and will develop a solid foundation for you to advance as a programmer.
Table of Contents (33 chapters)
1
Section 1: C Fundamentals
10
Section 2: Complex Data Types
19
Section 3: Memory Manipulation
22
Section 4: Input and Output
28
Section 5: Building Blocks for Larger Programs

Creating, typing, and saving your first C program

Let's begin creating our Hello, world! program.

Before we begin creating files, create a directory on your computer where you will save all of the work for this book. Perhaps you will create it in your $HOME directory, or in your Documents folder. My advice is to put it somewhere in a user directory of your choice. Let's go ahead with our program:

  1. Open a Command Prompt, Terminal window, or console (depending on your OS).
  2. Navigate to $HOME or ./Documents, or wherever you chose to work from, and create a directory for the programs you'll write in this book. Do this with the following command:
    $ mkdir PacktLearnC
  3. Make that directory your current working directory with the following command:
    $ cd PacktLearnC
  4. Make a new directory for this chapter with the following command:
    $ mkdir Chapter1_HelloWorld
  1. Make that directory your current working directory with the following command:
    $ cd Chapter1_HelloWorld
  2. Picking the text editor of your choice – any will do – open the text editor either from the command line or from the GUI (depending on both your OS and your preference of which one you wish to use):
    • From the command line, you might enter $ myEditor hello1.c, or just $ myEditor, and later, you will have to save the file as hello1.c in the current working directory.
  3. Enter the following program text exactly, all while paying attention to spacing, {} versus () versus "" (these double-quotation marks are the key next to the ; and : keys) versus <>, with particular attention being paid to #, \, ., and ;:
#include <stdio.h>

int main()
{
printf( "Hello, world!\n" );
return 0;
}
  1. Save your work and exit the editor.
  2. Verify that hello1.c exists by listing the directory and verifying that its file size is not zero.

Congratulations! You have completed your first editing phase of the program development cycle.