tags:

views:

286

answers:

9

I want to learn C languages and I'm running a Linux distro (Ubuntu) so I would like to know where can I begin?

I know some people will tell me to read K&R books or others but I want to pratice C, not theory. So I believe that reading C sources and changing some words will help me to understand. So what are the sources for a beginner?

A: 

4 Simple Steps to Learn C

  • Read K&R or some other C book. Reading C code is no good if you don't understand some fundamental concepts like pointers.
  • Write your own game (does not need to be anything complicated, a C port of GORILLA.BAS will do it)
  • Try to hack around in the Linux kernel (certainly not the highest quality C code around, but it is a very good example of a real-life C project)
  • You're a C pro now!
DrJokepu
ok, precise after five years 'you're a C pro now!', thx
toddoon
+4  A: 

First, add a "deb-src" line to your /etc/apt/sources.list file. Something like this, with the URL being the same as your normal lines (those starting with deb):

deb-src http://archive.ubuntu.com/ubuntu/ intrepid main universe

Then run "apt-get update". You can now get the source of any program with the following command:

apt-get source foo

where "foo" is the name of the package. To find which package contains a particular program, use "dpkg -S bin/program".

I'd suggest you start with the "hello" package, and then any program that you like to use. Probably best to start with small ones, they tend to be easier to understand. Perhaps "coreutils", or "grep".

Lars Wirzenius
Goog, good, thx!
toddoon
+2  A: 

If you want to practice C you should select some simple task you want solved and try to solve it. Reading kernel for the sake of reading it and altering it here and there will not be very helpful because you have no objective and because the kernel is a very complex thing and just altering it will likely lead you to a non-functioning kernel.

sharptooth
+1  A: 

This is the first Google hit on "C tutorial", I really think you'll learn quicker by starting out small, rather than diving into some realistically-sized project.

Real ("production") C code can easily be both long and complex, and I doubt that either helps out when you start from scratch to learn.

Failing that, feel free to browse e.g. Freshmeat for some project you find interesting, and download its code. This is a filtered listing, that only shows projects tagged "C".

unwind
+1  A: 

As suggested by sharptooth, you will get more mileage out of actually writing C than you will by just reading it. It's much more likely that you'll miss some of the subtle areas of the language (or any other language for that matter) if you're not actually confronted by compiler errors or bugs.

From memory there is quite a decent tutorial/introduction to C over at linuxchix.org.

Andrew Edgecombe
ok it is bookmarked
toddoon
A: 

You might enjoy trying ccan (think CPAN for perl, only C). A lot of very good gems are there, everything from discovering the frustrations associated with mmap(), to a very easy to use unit testing suite. Examples and tests are plentiful, which are a GREAT study guide for the self learner.

More importantly, you might ask "How can I study FLOSS code AND pick the brains of its developers ?". For that, you should really first read and work though K&R. That's going to take a little time :)

Who knows, you might even find a kernel hacker or two on the list ;)

Tim Post
+1  A: 

Code Reading is a book that could help you with reading C source code. It is not specific about C, but it includes the source code of many open source projects written in C and presents the most common idioms used by C developers. It could also assist you in learning how to read code.

kgiannakakis
Sounds like a great book; thanks.
Giovanni Galbo
Very good tips i am impatient to read it
toddoon
A: 

From a training perspective, other than K&R, I would recommend taking a look at two other books:

  • The C Puzzle Book by Alan R. Feuer. Working through the puzzles and comparing your solutions to the solutions in the book will give you a firmer grasp of the fundamentals of C, and will at least bring you to an intermediate level.
  • The C Answer Book by Tondo and Gimpel is, in my opinion, an excellent companion to K&R, since it provides solutions to all the exercises in K&R. I don't know how many C programmers have actually worked through the exercises in K&R, but The C Answer Book can help you navigate through them if you are so inclined.

Books and other training materials are no substitute for actual experience, but they do provide some sort of structure and direction when going to the next level. The good ones do, anyway. Hacking around the kernel would frustrate me if I was a beginner. I would train myself by learning the fundamentals and attempting to write my own code as much as possible.

Joe Suarez
ok good links i will look at these!
toddoon
A: 

I don't know what specifically you're looking for, but I briefly hacked on sound-juicer (apt-get source sound-juicer) and that code base was very easy to understand.

MighMoS
Ok thanx for the tips
toddoon