NO

Author Topic: How to learn C... so it sticks....  (Read 16649 times)

CommonTater

  • Guest
How to learn C... so it sticks....
« on: July 09, 2012, 03:00:06 AM »
Every so often I get a private letter asking what's the best way to learn C... 
 
OK... here it comes....
 
 Download and install the latest version of Pelles C. For 64bit Windows you want the x64 version, for everything else you want the x86 version.
 
 Read the help file... No joke, I really mean this... Read the help file! In there you will find instructions on creating your first project, some general information about the flavour of C Pelle's supports, a lot of detail on the libraries and headers included, detailed information about the IDE and more... Make yourself familiar with the contents so you know where to find things as you need them. This is all stuff you'll need to refer to everyday while working with Pelles C, there's no excuse not to familiarize yourself right up front.
 
 Get a good book on C... There are lots and lots of them. I used Teach Yourself C in 21 Days by Aitken for an introduction then followed up with The C Programming Language by Keernighan and Ritchie for more depth.
 
 Know that nobody ever learned C --or any other programming language-- by merely reading a book... and certainly not by watching videos or listening to e-books.  To get this to stay between your ears, you need to make a deliberate study... work page by page, re-read as often as necessary... type up all the examples and try all the quizzes... work with the code, change it, break it, fix it.. learn what it can and can't do... Study the text and the code until you understand them and then turn to the next page.  And, whatever you do, don't get in a hurry... stay the course if you want to learn.
 
If you've gotten to the end of your first book, immediately disaffuse yourself of the bright idea that you are suddenly a programmer.  Yes you are writing some code and you've done all the exercises in your books but programming is a lot more than simply writing a few algorythms. What you need to do now is practice and practice and more practice, honing your problem solving skills while writing ever more complex programs... Jumping ahead of your skill level will only frustrate you.
 
 Ok so now you're comfortable writing console programs... lets get on to some Gui stuff...
 
 Download the Windows SDK (Software Development Kit).  In this case you only need to install the Windows API documentation... the rest --headers, libraries, etc-- is already included with Pelles C.  The version linked is closest to the Headers and Libs supplied with Pelles C, so you want this version even though there are newer ones.
 
 Yep... Read the help file... again... This time you are getting familiar with the features of Windows API (Application Programming Interface) and learning to navigate around the SDK's 30,000+ pages. This is like the Pelles C help file, you're going to be in it a lot, so it pays to get familiar with it's content and how to find information when you need it.
 
 Now for a taste of windows GUI mode programming, where everything is a window and you create applications by stacking windows in windows.  Grab a copy of TheForger's Windows API Tutorial and start working through it.  Yes, it's all C, and yes, it's unlike any C programming you've seen so far. As before... work page by page, exercise by exercise, repeating as needed until it sinks in. Just like you did with the console mode stuff.
 
 Next, you should get a copy of Programming Windows by Peltzoid.  This is advanced windows, although it is slightly dated.  You should once again go page by page, exercise by exercise... just like before.

Of course all the books and tutorials you've accumulated in this process will become valuable reference sources for your future projects.   
 
Ok... so there it is, How to learn C so it sinks in.  If you take your time and learn carefully, you will make yourself into an intermediate level programmer... the good stuff all comes from practice, practice and more practice...

A couple of other helpful texts you might want to download...

c99  Information about the C-99 language standards
c11  Information about the C-11 language standards
uxguide  Windows user experience guidelines.

 
EDIT: Cleaned up text, added new links.


 
« Last Edit: October 23, 2012, 04:42:54 PM by CommonTater »

collectiva

  • Guest
Re: How to learn C... so it sticks....
« Reply #1 on: July 18, 2012, 11:54:46 AM »
Please visit the Site http://contest.collectiva.in/Contest/ContestTraining.aspx To learn Fundamentals of C Programming online video tutorials in Tamil. It is very useful for the Beginners.

CommonTater

  • Guest
Re: How to learn C... so it sticks....
« Reply #2 on: July 18, 2012, 02:20:21 PM »
Please visit the Site http://contest.collectiva.in/Contest/ContestTraining.aspx To learn Fundamentals of C Programming online video tutorials in Tamil. It is very useful for the Beginners.

Please read #4 above... Nobody learns C --or any other programming language-- from a video.  You can show someone something 30 times and they won't get it... make them do it once and they will understand.

tpekar

  • Guest
Re: How to learn C... so it sticks....
« Reply #3 on: July 25, 2012, 09:30:49 PM »
The best book for a beginner to learn C is "Workout C" by David Himmel.

CommonTater

  • Guest
Re: How to learn C... so it sticks....
« Reply #4 on: July 25, 2012, 10:19:30 PM »
The best book for a beginner to learn C is "Workout C" by David Himmel.

I can't fault the book... this is the first I've seen of it. 

But looking it up I notice it is based on Power C which is an old DOS 2.0 compiler that I doubt would run on any modern windows computer.  So, a question... how well do the lessons in the book translate to Pelles C or other C-99 and C-11 compilers?


Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: How to learn C... so it sticks....
« Reply #5 on: July 26, 2012, 07:07:40 AM »
The best book for a beginner to learn C is "Workout C" by David Himmel.

I can't fault the book... this is the first I've seen of it. 

But looking it up I notice it is based on Power C which is an old DOS 2.0 compiler that I doubt would run on any modern windows computer.  So, a question... how well do the lessons in the book translate to Pelles C or other C-99 and C-11 compilers?
As I mentioned at least a couple of times before, there is a big difference between learning to program using C and programing for Windows using (Pelle's C)...

I am a stern believer that people should not try and program for Windows (in C) before they they have learned the basics of the C programming language (and it's associated pitfalls, see our other newbie friend today).
For that, any book that teaches basic ANSI C and sticks with console output should be suited for this, some maybe a bit better than others and that's where the compiler being used shouldn't matter much.

Otherwise, it's a bit like starting to run and before someone has learned to walk, you just will fall flat on your face with every (other) step...

Ralf

And Power C is not a "DOS 2.0" compiler! Yes, it's around for almost 3 decades now, but it is still available for purchase (and the manual itself is probably worth the $20 for the basic compiler!)

CommonTater

  • Guest
Re: How to learn C... so it sticks....
« Reply #6 on: July 26, 2012, 09:59:09 AM »
Hi Ralf...
 
As I mentioned at least a couple of times before, there is a big difference between learning to program using C and programing for Windows using (Pelle's C)...

Absolutely... Windows API programming is an entire horse of a different colour.  Yes it's C but it ain't "normal" C. 
 
Quote
I am a stern believer that people should not try and program for Windows (in C) before they they have learned the basics of the C programming language (and it's associated pitfalls, see our other newbie friend today).

No argument... Like I said in the lead message, people need to understand general C programming before they even think about tackling Windows API... the results are, as you note, often more frustrating than anything else.
 
Quote
For that, any book that teaches basic ANSI C and sticks with console output should be suited for this, some maybe a bit better than others and that's where the compiler being used shouldn't matter much.

Here I will gently disagree with you.  On another forum I had repeated problems with people trying to get Turbo C (and maybe Power C) code to run on MinGW and Pelles.  There are differences on older compilers that lead to what we would consider sloppy programming... things like Turbo C letting you change string constants and differences in library function behaviours that cause problems.  (FWIW... this was a particular problem with students from India, where they still teach using 20 year old versions of Turbo C on MS-DOS based machines.)
 
While these older compilers may have been excellent tools in their day, I will suggest that when learning with newer compilers beginners should look for text books that teach "ANSI C" (C-89 or newer).  It saves a person from having to unlearn some pretty ugly practices gathered from pre-standards compilers.
 
I will otherwise take your word that Power C is OK...
 
Quote
And Power C is not a "DOS 2.0" compiler! Yes, it's around for almost 3 decades now, but it is still available for purchase (and the manual itself is probably worth the $20 for the basic compiler!)

OK, point taken...  but Pelle's help file is no slouch either :D
 
 

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: How to learn C... so it sticks....
« Reply #7 on: July 26, 2012, 06:12:59 PM »
Here I will gently disagree with you.  On another forum I had repeated problems with people trying to get Turbo C (and maybe Power C) code to run on MinGW and Pelles.  There are differences on older compilers that lead to what we would consider sloppy programming... things like Turbo C letting you change string constants and differences in library function behaviours that cause problems.  (FWIW... this was a particular problem with students from India, where they still teach using 20 year old versions of Turbo C on MS-DOS based machines.)
If a DOS based machine is all you have to work with, the using Turbo C is certainly a very good choice.
Problem is that "sloppy programming" can be done with any compiler, even with MinGW or Pelle's C...

Ralf

CommonTater

  • Guest
Re: How to learn C... so it sticks....
« Reply #8 on: July 26, 2012, 06:53:28 PM »
Hi again Ralf ...
 
This is getting interesting :D
 
Problem is that "sloppy programming" can be done with any compiler, even with MinGW or Pelle's C...

 Certainly can and I've even been known to do it from time to time...  ::)
 
Thing is we kept running into people who didn't understand why main() caused errors  but int main (void) did not or why changing constants would cause exceptions.  Their knowledge was superficial at best and some of them got quite adament that "It worked in class and it should work now" and such... never once realizing they'd been educated on antique compilers.  There were days when every other message was "Get rid of Turbo C and get something from this millenium". There were even Wall Street Journal articles about the problem.  It was really sad.
 
I won't argue with you that, in their day, these were excellent compilers but I will suggest their day is over and educational institutions and book publishers really do need to get up to speed.
 
« Last Edit: July 26, 2012, 07:02:39 PM by CommonTater »

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: How to learn C... so it sticks....
« Reply #9 on: July 26, 2012, 10:31:47 PM »
Hi again Ralf ...
 
This is getting interesting :D
Glad you enjoy it...  8)
Quote
Problem is that "sloppy programming" can be done with any compiler, even with MinGW or Pelle's C...
Certainly can and I've even been known to do it from time to time...  ::)
 
Thing is we kept running into people who didn't understand why main() caused errors  but int main (void) did not or why changing constants would cause exceptions.  Their knowledge was superficial at best and some of them got quite adament that "It worked in class and it should work now" and such... never once realizing they'd been educated on antique compilers.  There were days when every other message was "Get rid of Turbo C and get something from this millenium".
Well, but what the rational behind it? And for what purpose do you use Turbo C?
As for your main() example, it will work in Pelle's C just as Turbo C (or other DOS area compilers) will bark at you with warnings about that. It's just a matter of setting the warning level and/or just ignoring warnings a compiler is throwing at you. People need to realize that the fact that you end up with an executable doesn't mean that there aren't any problems with the program. And if a teacher lets something like this slip or even encourages/teaches something like this, (s)he needs to get a kick in the ...
Quote
There were even Wall Street Journal articles about the problem.  It was really sad.
Well, it is, but I fail to see any reference to anything C (or programming) related in that article.
Not to mention that I had US college grads fails similar simple tests when I was dong job interviews at my former employer...
Quote
I won't argue with you that, in their day, these were excellent compilers but I will suggest their day is over and educational institutions and book publishers really do need to get up to speed.
I would actually contest that. Instead, I think it would be best to actually "get back to basics" and start teaching programming again without all the modern fluff. A lot of that is simple distracting of understanding the basics of programming.

Ralf

CommonTater

  • Guest
Re: How to learn C... so it sticks....
« Reply #10 on: July 26, 2012, 11:42:30 PM »
This is getting interesting :D
Glad you enjoy it...  8)

Well, Im hoping you do too... I always enjoy a good conversation.

Quote
Well, but what the rational behind it? And for what purpose do you use Turbo C?
In the case of this bunch on the other forum, I think the rationale was "We've always done it this way" or perhaps "Hey we got all this free, so..."  I doubt there's a good reason to use such old tools...
 
Quote
And if a teacher lets something like this slip or even encourages/teaches something like this, (s)he needs to get a kick in the ...

We had some of that too... A couple of the students told us the things they were being taught and I simply couldn't believe my eyes... Borland's BGI graphics??? Really... And a few of the teachers were apparently pretty out to lunch on some of the assignments as well.  I won't guess how generalized it was, but if it's widespread, I think we're in more trouble than we know...
 

Quote
There were even Wall Street Journal articles about the problem.  It was really sad.
Well, it is, but I fail to see any reference to anything C (or programming) related in that article.
Not to mention that I had US college grads fails similar simple tests when I was dong job interviews at my former employer...

 
Not specifically in the articles, but a few of the guys on the forum went to the schools mentioned.
 

Quote
I would actually contest that. Instead, I think it would be best to actually "get back to basics" and start teaching programming again without all the modern fluff. A lot of that is simple distracting of understanding the basics of programming.

Abosolutely.  On this we agree.  But I would add they should do it on modern compilers, like Pelles or MinGW...
 
Think of what could happen if people were properly trained in the basics on high end compilers... they'll only get better as they learn more.  :D As my father used to say: "A craftsman is only as good as his tools."
 
 
 

inobor

  • Guest
Re: How to learn C... so it sticks....
« Reply #11 on: November 08, 2012, 06:58:26 AM »
Well, if I may add to this... Borland C was fantastic for me and BGI
was nice but a bit slow :) If you put your hands into guts of what
was called a videoRAM of CGI or Hercules - was my case - your picture is drawn
as quickly as hell. DOS was relatively simple and let you go as deep
as you like and make you really excited. Unfortunately this time
has gone. I am probably lamenting too much (or just being lazy)
but go equally deeply with modern operating systems you should
spend a way way more time. IMHO all these GTK, Qt, FLTK, you name
it, is nothing but an obstacle to learn the programming
 >:(

CommonTater

  • Guest
Re: How to learn C... so it sticks....
« Reply #12 on: November 08, 2012, 09:47:17 AM »
Well, if I may add to this... Borland C was fantastic for me and BGI
was nice but a bit slow :)

Exactly... and that's why I've not recommended any of these ridiculous 3rd party graphics libraries... that's Linux stuff and they can have it.

Start with Cin21 and/or K&R ... don't even worry about graphics.  Just learn C.

Once you get a bit more advanced then you can climb into the Windows API (which is NOT gtk, qt, etc) and learn to write GUI mode programs using the Windows native API and it's controls. 

As for BGI ... deader than a doornail, and rightfully so.  Since win2000, applications do not have direct access to hardware (required by BGI).  Console programs don't do graphics.  Since Vista, console programs don't even do full screen.

While I'm sure some will tell you the old days are better, and that you're better off learning on some ancient boatanchor system... the fact is that what you have before you today (probably XP or newer) is what you got... so learn it.

migf1

  • Guest
Re: How to learn C... so it sticks....
« Reply #13 on: November 25, 2012, 01:42:19 PM »
C Programming, A Modern Approach, 2nd Edition, by N.K.King
(amazon link)

Imho, King's book is one of the best, if not the best, introductory book in C programming (and arguably in programming in general). It covers both ANSI C and ISO C99. I only wish books of such quality have been around when I was taught the original K&R C programming language (it was back in 1986, and all universities were using K&R's as their textbook).
 
I also encourage all beginners with genuine interest in working in the CS field in the future, to focus on learning the core language first (no APIs). Ideally starting by working on the command-line shell, before moving to an IDE. IDEs use the command-line shell anyways, so by knowing its "mechanics" you know how to to setup any IDE to work with any compiler. You'll also have a solid grasp of the process that begins with writing the source code, and ends with loading the executable (editor-preprocessor/compiler/assembler-linker-loader).

Those are fundamentals, and IMHO there's no excuse for any programmer not to be familiar with them.

Jacob Navia's C Tutorial, available on his lcc-win32 compiler homepage, is also n darn good reading for any beginner, although not that comprehensive as King's book (btw, correct me if I am wrong, I believe Pelles-C started as an lcc fork, right?). His Advanced C Programming with lcc-win32 is an even more enjoyable read, but diverges significantly from the standard features of the language (still a must-read in my humble opinion).

On a side note (for the better or for the worse) the by far most ported C compiler on all platforms is gcc, so it only comes natural for most introductory textbooks to cover its tool-chain. Its most widespread port on Windows is MinGW, however it's a minimalistic port. For a full-blown gcc port on Windows, one could install Cygwin (and that's may not be trivial, especially for beginners).

That being said, Pelles-C (as any compiler) comes with its own command-line tool-chain, thus it is perfectly "do-able" to work it from the command-line, once you get familiar with the tool-chain... it's all in the Help files (actually that's how I mostly use it, via a rather heavily customized Notepad++ as IDE).

As they say, "C is easy to learn, hard to master" and I fully agree ;) I know how big is the urge for beginners to do visually pleasing stuff putting the minimum possible effort, and that's fine with me as long as we talk about either hobbyists or well established professionals. But I really think this is NOT the way to go if you are a CS student.

PS. How come nobody mentioned delorie's DJGPP for DOS so far? An awsome port of the gcc tool-chain, with impressive documentation too.
« Last Edit: November 25, 2012, 01:51:27 PM by migf1 »

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: How to learn C... so it sticks....
« Reply #14 on: November 25, 2012, 06:51:37 PM »
C Programming, A Modern Approach, 2nd Edition, by N.K.King
(amazon link)

Imho, King's book is one of the best, if not the best, introductory book in C programming (and arguably in programming in general). It covers both ANSI C and ISO C99. I only wish books of such quality have been around when I was taught the original K&R C programming language (it was back in 1986, and all universities were using K&R's as their textbook).
Well, they simply couldn't, as in '86, ANSI C did not "exist" (officially) yet as the first ANSI C standard was ratified in 1989 (C89), with slight updates in 1990 (C90). And it would have taken a lot of magic to forsee C99...  ;)

Ralf