Making Progress with C Programming

It has been a while since my last post but I have been busy with C and various other things. I changed my web hosting company as my previous one was a bit of a nightmare - ixwebhosting.com. Avoid like the plague. But of course more importantly, I have been studying C Programming. As mentioned before I was considering doing the VTC Video Training course. Well, consideration is over and the course is complete. It was pretty easy but I had already studied Larry Ullman’s book on C Programming so that helped and I also was also struggling with Computer Fundamentals and Programming in C (by Pradip Dey and Manas Ghosh). I gave up. At least temporarily. Hence, the VTC course and I splashed out and bought another two text books. C Programming by Kernighan and Ritchie and The C Answer Book by Todo and Gimpel.

In the VTC course all went well until the chapter about Using C on the Web. The problem here was that I couldn’t successfully install IIS and therefore couldn’t do the examples in this Chapter. I contacted the author and he tried to help me but I haven’t managed to get it working yet. I’ll discuss that in another post. If I had to criticize this course though, I would say that there aren’t enough exercises, hardly any actually but I guess it is not a fair criticism as you are supposed to use this course with the above mentioned K & R book which has plenty of exercises. One more criticism which I think is a fair point, the final Input and Output chapter is basically just a list and was quite tedious to go through. Other than that, the course was quite fun.

When I make progress in the K&R book I will give you some feedback.

PHP from Scratch has moved.

As I am sure many of you noticed, my site was the victim of some sort of malware. It wasn’t pretty and I didn’t have time t0 resolve the issue. Until now. Not that I really have the time now.

I think it is fair to say that phpfromscratch has moved in more ways than one. Physically, it has moved up from a sub directory to the main domain. I don’t know what I was thinking putting this in a sub directory.

And the other way it has shifted is the subject matter. Because of my new job, I have to study C Programming, so I will be focusing on it until I am proficient at it and hopefully after that I can get back to studying php.

For and While Loops

I think the while loop is fairly easy to follow but the for loop had me going loopy. I just didn’t get it but thanks to the kind people over at CProgramming.com, a friend of mine and sheer determination, I managed to figure it out. I was having trouble understanding the logic of the following program.

int i;
for(i = 5; ++i; i -= 3)
printf(”%d “, i);

The solution is below:

i is declared as an integer and in the while loop is given a value of 5 which is true and that is incremented by the ++i to 6 which is printed and then the value is changed to 3 then incremented to 4 and therefore it is also printed and then the value is changed to 1 then incremented to 2 which is true and therefore printed and the value is changed to -1 and it is incremented to 0 which is false and therefore not printed and the loop ends.

I think I know where my confusion was coming from. The first part of the loop is just the initialization and then the second part is the condition which gets executed, changes the value of i and is also evaluated as true or false depending on its value being zero or non-zero and if it is true it will go to the third part be executed and go back to second part skipping the first part because it is merely an initialization. The loop is basically between the second two parts.

Sorry for the ramble. I will put my confusion in note form below.

1/ I thought the first part was a condition for some reason. (mistake - just initialization)
2/ I didn’t realize that the second part acts as both a condition and changes the value. (mistake - it does)
3/ I though that after the third part it goes back to the first part. (mistake - it goes back to the second part)

I was also given the following piece of advice in the forum and by my friend. It was also in my text but if you, like me, are having trouble with the for loop please check my mistakes above. The advice and a great thing to remember is as follows:
for(initialization; condition; increment) {
code;
}

is the same as
initialization;
while(condition) {
code;
increment;
}

C Programming and octals etc. [010 = 8]

Computer Fundamentals and Programming in C by Pradip Dey and Manas GhoshMy boss has provided me with a new book so I have to study it. It is called Computer Fundamentals and Programming in C by Pradip Dey and Manas Ghosh. I have to admit that it is much heavier than Larry Ullman’s and is causing me a few headaches. The first 7 chapters of the book deal with computer fundamentals and the latter chapters with C Progamming. So I boss told me to start with Chapter 8 but that studying the preceding chapters would also benefit be greatly in helping me to understand computers better.

Well, I started off on Chapter 8 as I am constrained by time. I have about 3 months to learn C to a certain level. Unfortunately it is what clear what that level is.

Anyway, I came across my first problem came on page 220 (not that I completely understood the preceding pages). There is a small program and we have to use it to test our progress. It was a simple program but I couldn’t understand the result which I am fairly sure is an important aspect of studying.

The program is as follows

int a=010;

printf(”/n a=%d, a);

I know that %d means integer so my first though was that the result of this program should have been 010 so I was stuck. I went back to the previous chapters that I had skipped and looked through information about binary, hexadecimal and such things which was good because I now feel I can deal with them and understand the concept which I didn’t yesterday but I didn’t find the answer to my problem there.

I did find the answer though. Apparently in C, numbers preceded by the the digit 0 are octals. That means if you convert the octal 010 it becomes 8 when represented by an integer.

And that was the result. Phew!

Print() Signifiers Table (Printable)

print() signifiers cheat sheetThere are not so many print() signifiers but even so I have found myself checking their meanings regularly. Sometimes just to be sure of their meaning others because I just haven’t learned them yet. To save time flicking through pages I decided to create a little cheat sheet to print out which I am sharing with you here. I have printed it out on a business card sized piece of paper so it is easy to carry around with me but you could print it out larger and place it somewhere you will often see it.

VTC verses Larry Ullman

The title of this post sounds very dramatic but in my study of C Programming I have decided to use VTC’s video training course and C Programming (Visual QuickStart Guide) by Larry Ullman and Marc Liyanage for reasons discussed in a previous post.

On page four of the book it states that some C source code files will use the format

main() {

or

void main() {

but they are not C99 compliant and will work inconsistently across different compilers. It states that the book will use the formal, standard

int main() {

.

The VTC video training course used

main(){

. So I guess this is one point for Larry Ullman.

I will probably concentrate on the book for now and when or if I am able to complete it I will switch to the VTC course. I feel the more knowledge I have before subscribing to VTC I have the more use I can make of it.

VTC C Programming - First Impression

As I had loaned my friend my C Programming text book, thinking that I might never get around to actually using it, I started off by using the free lessons on the VTC web site. The lessons were easy to follow and there was even one small test that wasn’t particularly difficult either. Actually, I think I’d have to say it was easy. That said, I did somehow manage to make a mistake and wrote to VTC to try figure out what I had done wrong.

The reply was taking quite a while so I went over it again and discovered my mistake. I discovered that just changing the code is not enough. You must also re-compile it for it to work. It was a valuable lesson.

Regarding the reply from VTC, I think that within a day I received a reply telling me that they have contacted the author about this problem and that they will get back to me. I promptly replied that I had discovered my mistake by myself and that further help was unnecessary. The author replied within about one more day and he told me what I had probably done wrong.

I think it should have been made clearer that changed code must be compiled again to work.

I had no other criticisms about VTC (which is pretty good for me) until I started using Larry Ullman’s book. (See next post)

VTC C Programming Free Videos

Below are a list of the videos provided by VTC to help you learn C language. The hyperlinked lessons are free and you can watch them directly from this site just by clicking on the link. To view the others you will of course have to subscribe to VTC but it is very reasonable at about $30/ month or $250/year and I believe it also gives you access to the other videos in their library which contains over 60,000 videos and covers a broad range of topics.

Of course the authors vary as I am sure does the quality. I will provide feedback in my later posts.

C Programming 2007

The C Programming Language is the foundation of nearly all modern computer languages. C is a “low level” simple language that can be used to create the most elegant of applications and operating systems. Most of today’s commercial applications and operating systems have the C language at their core. VTC author Tim Heagarty explains the history and mechanics of the language and gives practical advice on its use in the commercial world. To begin learning simply click the links.

Introducing C

Introduction

Short History of C

C on Windows

Testing Visual C++ 2005 Express Edition

C on Linux

Testing GNU CPP

What a Compiler Is

First Steps

Hello World

Entering The Program Pt.1

Entering The Program Pt.2

Compile & Run

Examine Each Line

First Program Assignment

First Program Answer

Types/Operators & Expressions

Types/Operators & Expressions

Variable Names

Data Types & Sizes

Constants

Declarations

Arithmetic Operators

Relational & Logical Operators Pt.1

Relational & Logical Operators Pt.2

Type Conversions

Increment & decrement Operators

Bitwise Operators

Assignment Operators & Expressions

Conditional Expressions

Precedence & Order of Evaluations

Control Flow

Control Flow

Statements & Blocks

If-Else

Else-If Pt.1

Else-If Pt.2

Switch

Loops - While

Loops - For

Loops - Do-While

Break & Continue

Goto & Labels

Functions & Program Structure

Functions & Program Structure

Basics of Functions Pt.1

Basics of Functions Pt.1

Functions Returning Non-integers

External Variables

Scope Rules

Header Files

Static Variables Pt.1

Static Variables Pt.2

Register Variables

Block Structure

Initialization

Recursion

The C Preprocessor

Pointers & Arrays

Pointers & Arrays

Pointers & Addresses Pt.1

Pointers & Addresses Pt.2

Pointers & Function Arguments

Pointers & Arrays

Address Arithmetic

Character Pointers & Functions

Pointer Arrays/Pointers to Pointers

Multi-dimensional Arrays

Initialization of Pointer Arrays

Pointers vs. Multi-dimensional Arrays

Command-line Arguments

Pointers to Functions

Complicated Declarations

Structures

Structures

Basics of Structures Pt.1

Basics of Structures Pt.2

Structures & Functions

Arrays of Structures

Pointers to Structures

Typedef

Unions

Bit-fields

Input & Output

Input & Output

Standard Input & Output

Formatted Output-Printf Pt.1

Formatted Output-Printf Pt.2

Variable Length Argument Lists

Formatted Input Scanf

File Access

Error Handling Stderr & Exit

Line Input & Output

Miscellaneous Functions

Using C on the Web

Using C on the WWW With CGI

Basics of CGI Pt.1

Basics of CGI Pt.2

Preparing For C & CGI Pt.1

Preparing For C & CGI Pt.2

Hello World on CGI

Functions For C on WWW

Writing A Form For CGI Pt.1

Writing A Form For CGI Pt.2

Writing A Form For CGI Pt.3

Display & Use Environment Vars Pt.1

Display & Use Environment Vars Pt.2

The UNIX System Interface

The UNIX System Interface

Low Level I/O Read & Write

Open/Create/Close/Unlink

Random Access Lseek

Input & Output

Input & Output Pt.1

Input & Output Pt.2

File I/O & Character I/O

Direct I/O & Error Handling

Character Class Tests

String Functions Pt.1

String Functions Pt.2

Math & Utility

& Diagnostics/Arg Lists & Signals Pt.1Diagnostics/Arg Lists & Signals Pt.2Date & Time Functions Pt.1

Date & Time Functions Pt.2

Defined Limits

&

Review

Review

Credits

About this Author

Beginning C Programming

C ProgrammingAs I am a fan of Larry Ullman and also because I received the book “C Programming (Visual QuickStart Guide)” which he co-authored with Marc Liyanage from one of his free book giveaways I will be using this text. I have noticed that this book hasn’t received as much praise as Ullman’s other books but hell I didn’t pay for it.

I have also gone over the first few chapters (free) from the VTC site and I will probably subscribe to that as I need all the help I can get.

Blog is not dead, just taking a break.

Well, I guess many of you probably felt that this blog has been abandoned and in truth I thought that perhaps I would have to abandon it as I am pretty short of time. I have been very busy working and living, getting married and all sorts of things.

Since my last post I have been give the opportunity to work as a programmer but as I am not a programmer and don’t really have much knowledge of programming it is going to be quite a challenge. Unfortunately my new job is not PHP but rather C. A little antiquated it may be but it will be my base I am told.  I have been given three months to study this language by myself and if that goes well I will go to the office every day for another 3 months to continue my study. This will be a probationary period during which time I will have to prove myself. If I don’t I will be back in square one.  In my next post I will describe how I intend to go about studying C Progamming and over the course of the next & months or so you will be able to follow my progress.

Wish me luck!