Take this

Software Development / Web Design

C Programming For Beginners

Learn C in ten easy steps on Windows, Mac OS X or Linux


The fastest, easiest way to learn to program C on a Mac or Windows. This course will teach you to program the C language from the ground up. You will learn everything from the very fundamentals of programming right through to the complexities of pointers, addresses and File IO. Maybe you've tried to master C before but failed. Or maybe you are new to C or new to programming. If so, this is the course for you!

C is one of the most important of all programming languages. It is used to program desktop applications, compilers, tools and utilities and even hardware devices. The C language is fast and efficient – but it can be hard to learn. Unless you use this course. This course begins with a gentle introduction to C but quickly moves on to explain some of its most confusing features: everything from C's 'scoping' rules to the curious connection between arrays and memory addresses. By the end of the course you will have a deep understanding both of the C language itself and also of the underlying 'architecture' of your computer. 

Full details


  • Getting Ready
    Welcome to the Course
    C is an important cross-platform programming language. In this video, I provide a quick introduction to the language and how to learn it using this course.
    C Editors and IDEs
    In order to write C programs you will need a suitable editor or IDE (Integrated Development Environment). Here are a few suggestions…
    Install CodeLite
    In this course I will generally use the free CodeLite C editor which is available for OS X, Windows and Linux. This video shows how to get CodeLite installed on your computer.
    Install C compiler on a Mac
    If you are using a Mac you may need to download some additional tools so an editor such as CodeLite is able to find a compiler to build and run your programs.
    Introduction to CodeLite
    Let’s take a quick look at the features of the CodeLite editor – from syntax colouring to keyboard shortcuts. CodeLite makes light work of creating C projects on Windows and OS X.
    Programming C with NetBeans
    Maybe you are already use the NetBeans IDE for Java programming. Or maybe you'd just like to use NetBeans as your C environment. Here I explain how to get up and running.
    Importing Projects Into NetBeans
    There are various ways of importing source code into NetBeans. Here I show a simple way of creating a NetBeans C project using the files from one of my sample projects.
    Compiling C Programs at the System Prompt
    You don't need to use an IDE at all. If you are having problems installing an IDE or if you'd prefer to use a simple text editor, you can do so – and compile your programs in a System or Terminal window.
    Using Visual Studio
    If you are using Windows, Microsoft’s Visual Studio (even the free edition) may be used to create C projects. Here I explain how to do that.
    The Little Book Of C
    C Source Code
    C Programming FAQ
  • C Programming Basics
    A First Program - Hello world
    Here I take a look at a simple program that just displays “Hello world” and discover that even a few lines of C code illustrate a number of important features of the C language.
    Arguments and Return Values
    Some “Hello world” programs are more complex than others. Here I look at a program that takes some data as ‘arguments’ and returns a value.
    Passing Commandline Arguments to Your Program
    Here I explain how to pass arguments from the commandline (or Terminal) to your program.
    How to Open a Command Prompt on Windows or OS X
    If you don’t know how to open a command window on Windows or the Terminal on OS X and use it to run your programs, this lesson explains all.
    The printf() function lets you display the output from your program. It’s a very useful function but must be used with care – as I explain here.
    You can document your code with comments that are ignored by the compiler. Here I explain two types of comments.
  • Variables, Constants and Types
    Variables and Types
    Variables are identifiers whose values may vary during the running of your program. This video explains the basics of variables and their types in C.
    Integers and Floating Point Numbers
    You may do calculations with both full numbers – integers – and fractional numbers – floating points. But be careful: the end results may not be what you expect!
    If you want to create identifiers to store values that are not expected to change during the execution of a program, you can #define them.
    More About Constants
    Identifiers that are created using #define are often used as ‘constants’ – but, in fact, there is an alternative – using the keyword ‘const’. Here I explain the difference.
    Naming Conventions
    What should you call your variables and constants? Here I consider some of the naming conventions adopted by man C programmers.
  • Operators, Tests and User Input
    Operators - Equality and Assignment
    There are two ‘equals’ operators in C – one uses a single equals sign to assign a value to a variable. Another uses two equals signs to test for equality. Here I explain the difference.
    Operators - Tests and Comparisons
    You will frequently need to make comparisons between one value and some other value. C has a number of ‘relational operators’ to help you do this.
    Compound Assignment Operators
    Some assignment operators in C perform a calculation prior to assigning the result to a variable. These are called ‘compound assignment operators’.
    Increment and Decrement Operators
    You can use ++ and – to add and subtract 1 from a variable. But be careful – you can put these operators either before or after a variable and the position matters!
    If and Else Tests
    There are times when you need to take different actions according to some test condition. Here I explain how to use if..else tests.
    Problems with gets() and fgets()
    It may seem easy to get input with gets() but this may cause problems. The fgets() function is a safer alternative – but that too may cause its own problems, as I explain here.
    Input, Buffers and Flushing
    Sometimes you may have more data lurking in the dark corners of your computer than you are expecting. Here I explain some of the mysteries of buffers and why they need to be flushed.
    My Own Line-reading Function
    Here I look at two possible ways of writing a function that safely reads in characters entered at the command prompt and also flushes any unneeded characters from the buffer.
    Logical Operators
    If you need to chain together conditions when making tests, you need to use C’s ‘logical operators’.
  • Functions, Arguments and Switch
    We’ve used functions from the very start of this course. In this lesson I explain more about what functions are and how they really work.
    You can pass data to functions are arguments that are assigned to ‘named parameters’. Here I explain the nitty-gritty details of arguments .
    Switch Statements
    There may be times when you need to take many different possible actions depending on the value of some variable. The switch statement can help out.
    Switch Statements in More Detail
    In this lesson I look at more examples of switch statements, including some options that are only available with some C compilers.
  • Arrays, Loops and Break
    Arrays are sequential collections. You can use arrays to store lists of chars, ints and other types of data. Here I explain the fundamentals.
    Initializing Arrays
    You can add elements to an array at the same time the array is declared. Here I show how to do this and I also explain how the results of calculations may change according to the ‘precedence’ of operators.
    'While' Loops
    Sometimes you might want to run some code not for a predetermined number of times but for just as long as some condition remains true. You can use a ‘while’ loop to do this.
    'Do while' Loops
    In some circumstances the code in a ‘while’ may never be run. If you want to ensure that your code is always run at least once, use a ‘do..while’ loop.
    Sometimes it is useful to break out of a loop even if the loop’s test condition is not false. Here I explain how to use break in a ‘while’ or ‘for’ loop.
    Break and Continue
    Sometimes you may want to break from a loop once but then continue running the loop afterwards. Here I explain the difference between ‘break’ and ‘continue’.
    Multidimensional Arrays
    Arrays can have multiple dimensions to let you start arrays inside arrays. Here I explain how you can think of a two-dimensional array as being a bit like a spreadsheet with intersecting rows and columns.
  • Strings, Chars and Pointers
    Strings, Pointers and Addresses
    In order to understand strings in C you need to understand how computer memory can be represented by ‘addresses’ and how pointer variables can refer to those addresses.
    Null-terminated Strings
    Many programming languages have a dedicated string data-type. Here we revise the essential features of C strings and explain the significance of its lack of a string type.
    Char Arrays and Pointers
    At first sight there may seem to be no difference between an array of chars such as char str[] and a char-pointer such as char *str. In fact the difference is profound and important.
    Arrays, Pointers and Assignment
    Here I look at some more examples of using arrays and pointers and consider why you can assign to a pointer variable but not to an array name.
    Strings and Functions, Stack and Heap
    How do you return strings from functions? Let's find out. We also look at the importance of understanding the ‘stack and ‘heap’ in your computer’s memory.
    String Functions
    C compilers come with ready-to-use string functions. Here I look at some of the traditional functions as well as some more modern alternatives.
    Char Functions
    There are also functions that let you analyse individual characters in order to determine to which category each char belongs.
    Chars and Strings
    What is the difference between ‘x’ and “x”? They may look almost identical but, in fact, they are completely different – as this lesson explains.
  • Structs, Enums, Header Files and Scope
    Let’s imagine that you want to create a catalogue of your CD collection in which each record contains a name, the artist name, the number of tacks and a user rating. Here I explain how structs can help.
    C lets you define your own named types. This makes it possible to create type names for everything from an int to a string to a custom record or struct.
    Enums let you created groups of named constants that can help to document your code. Here I explain their value – and their limitations.
    Header Files
    What is the purpose of the ‘.h’ header files that most C programs include? Here I explain why header files are useful and how they are used during the compilation of your programs.
    A Custom Header File
    Here I look at an example of a header file that provides access to a set of functions and constants that I have written.
    ‘Scope’ defines the visibility of functions and variables to your code. Here I explain local and global scope and look at the scoping of two variables with the same name.
    Scope and External Files
    What is the scope of functions declared in external files – that is, functions that are in different files but the same project?
    Static Functions and Variables
    Sometimes you may want your functions to be ‘private’ – hidden from code in other files. Here I explain how static functions can do this, and I also explain static variables.
    Compiling from the Commandline
    To understand better how the compiler and linker work and how the compiler may rely on information from header files, try compiling your projects at the system prompt.
  • File-Handling
    Opening and Closing Files
    In this step we look at file operations. In this video I explain how to open and close disk files in order to save and load data to and from them.
    File Modes
    When you open a file you can use a short string to indicate the file ‘mode’. A file mode may make a file available for reading, writing or appending in text or binary format.
    Reading and Writing a Text File
    Here I go through the code in a sample project to show how text can be saved to and loaded from a file, how the file contents can be erased and how the file itself can be deleted.
    Count Lines in Text File
    Once you’ve opened a text file you may want to do something with the text it contains. In this video I show how to count the number of lines in a file.
    Search in a Text File
    Now you know how to read and write text files you can write programs to process the text in a variety of ways – for example, to search for words in a file or encrypt its contents.
  • Binary Fles and Memory Allocation
    Binary Files
    Not all files contain plain text. Some files may contain binary data – for example, if I were to save a CD database to disk, the data stored in each CD struct would have a binary representation. This video explains the basics.
    Allocating and Freeing Memory
    Sometimes you need to allocate memory dynamically. But once you’ve finished with that memory you need to free it. This lesson gives an example of code that does this.
    Types and Type Casts
    The C language provides a number of standard data types. Sometimes it is useful to treat one type as another type. In this lesson I explain the hows and whys of ‘type-casting’.
    Creating a CD Database
    The final project in this course creates a database of CD structs that are saved in a binary file on disk. This video introduces you to this project.
    Saving and Loading Records in a Binary File
    Here I explain how to save a collection of records (structs) into a binary data file and how to calculate the number of records stored before allocating memory when reading them in again.
    Adding Records to a Binary File
    Here I explain how to create a new CD struct in memory and then append its data to the end of an existing binary file storing CD records.
    Modifying Records in a Binary File
    Finally I show an example of how to find a record in a binary file and modify the data it contains. You can use the sample program as a basis for your own data-saving application.
  • Conclusion
    And Finally...
    We’ve covered a lot of ground in the course on C programming. Now it’s time to move on…
  • Quizzes and Answers
    C Quiz Questions
    C Quiz Answers

Similar Courses

More Courses by this Instructor