
Ask HN: What are some good resources for learning C? - arte
So far I&#x27;ve only come across scripting languages (Python, Node.js). I&#x27;d like to learn to program in C, for a number of reasons, but I&#x27;m not sure where to start.
======
jeffwass
K&R "The C Programming Language" is a classic. If you're serious about
learning C this book should definitely be in your collection. It's the book
most C programmers have cut their teeth on over the past several decades,
written by the guys who wrote the language itself. (Though go for the most-
current ANSI version). If you already know basics of programming methods from
Python or JS, you'll be able to handle this book. Make sure to do the
exercises!

Beyond that, it would depend what you're hoping to do with C. Eg, Linux kernel
hacking? Optimized Python numpy routines?

There also are some recent books that focus on writing 'modern' and also safer
C code, particularly with regard to usage of pointers. There are some links on
Amazon and O'Reilly that may be helpful (I haven't read any so can't give
recommendations)

~~~
erbdex
> Linux kernel hacking?

An excellent resource here as a beginner would be-
[http://www.advancedlinuxprogramming.com/](http://www.advancedlinuxprogramming.com/)

~~~
vezzy-fnord
Pretty sure that one's for userspace programming. In which case, I'd recommend
_The Linux Programming Interface_ instead, which is written by the same person
who maintains the Linux man-pages.

There isn't much of a central source on kernel hacking that isn't outdated by
now, though some reasonably good books on device drivers are still out there
and relevant. Beyond that, reading the kernel's Documentation directory, LWN
articles and the recent "Linux Insides" series being posted here is your best
bet, along with stalking the LKML, of course.

------
J_Darnley
I have seen a few people suggest:
[http://c.learncodethehardway.org/book/](http://c.learncodethehardway.org/book/)

I bookmarked this discussion a little while ago which has several good links:
[https://news.ycombinator.com/item?id=9333520](https://news.ycombinator.com/item?id=9333520)

My suggestion is always to work on a real project but for that you need to
know the basics of course.

------
Canada
I enjoyed Mastering Algorithms With C. After going through that book I was
able to actually get things done. I recommend this because it walks through
the implementation of basic data structures that you will be working with no
matter what you're doing.

K&R is a good reference, but I only found it useful after I knew enough to
actually get things done. I didn't find it good to learn with, and I was
already proficient in a couple of scripting languages.

I also recommend Richard Stevens books. Advanced Unix Programming and Unix
Network Programming are excellent. I'm not sure what you want to work on, so
that might not be relevant.

For studying how non-trivial things are implemented I like TCP/IP Illustrated
Volume 2, and The Design and Implementation of the Freebsd Operating System.

One of the things you're going to find about C that's different from higher
level languages is that it's so minimal that you're going to have to build up
a personal library of code to get things done.

For code samples, I like to look at OpenBSD. It's all in one place and there's
less cruft than most of the alternatives. This is useful because while the key
tasks of a particular program might be described well in one of the books I
mentioned, it's not the same as a real modern program. I've found it really
helpful to actually look at something that's stood the test of time for
inspiration. Also, it's man pages are awesome. I look at them often even when
writing code on other operating systems.

And remember, valgrind is your friend.

~~~
arte
Thanks, this was very useful.

------
selleck
I am currently going through CS50 online. You can join through edX or here:

[https://cs50.harvard.edu/](https://cs50.harvard.edu/)

Pretty good first steps intro that eventually goes into algorithms and data
structures.

------
rhgraysonii
As someone who has tried this myself, there are no solid 'tutorials' or
'guides'. Unless you are extremely versed in documentation-absorption it will
be quite the uphill battle.

That said, if one of your reasons isn't 'iOS' (in which I would recommend
Swift anyways), and you are instead moreso interested in learning a systems
language period, I would heavily recommend diving into Rust.

The documentation/introduction book is wonderfully written and a breeze to go
through. I have found the Rust team to be a wonderful group of guys that are
extremely responsive on SO, IRC, etc.

HN users pcwalton and steveklabnik both have many wonderful comments in Rust
threads that go into the minutiae of why it is so powerful. I had found
steveklabnik's book "Rust for Rubyists" wonderful, but it is since outdated
since the official Rust book has become concentration (www.rustforrubyists.com
confirms this) but the book includes some 'ruby inside of rust' examples etc.

Good luck in your journey!

~~~
steveklabnik
Thank you so much for the kind words <3

While I did take the site down, you can find the old source for Rust for
Rubyists at
[https://github.com/steveklabnik/rust_for_rubyists](https://github.com/steveklabnik/rust_for_rubyists)
still.

~~~
rhgraysonii
No problem. Keep up the wonderful work :)

------
kazinator
There are no good resources for learning C. All the good, accurate books on C
do not serve as tutorials.

It is impossible to write a tutorial in C that:

\- targets newbies (particularly programming newbies);

\- is comprehensible to that target audience; and

\- _isn 't_ chock full of inaccuracies and outright lies that have to be
unlearned later.

Sorry, no space here to prove this, but anyway, since it is impossible, one
doesn't exist. So, good news, you don't have to waste time looking for it.

Use a reliable _reference_ instead and struggle along for a bit.

I would recommend Harbison and Steele's _C: A Reference Manual_ :
[http://careferencemanual.com/](http://careferencemanual.com/)

(Yes, it's _that_ Guy Steele.)

~~~
Apocryphon
What's wrong with K&R?

~~~
kazinator
Firstly, the K&R2 is outdated. It was published in 1988, a year before ANSI C.
It has not been updated since. As a reference, it serves only long-time
programmers who steadfastly stick to ISO C 90.

The K&R and K&R2 can be likened to sales brochures for the C language, which
promote the language to users of other systems programming languages and
provide a mini-reference to get them started.

I started learning C circa 1990 from K&R2. A few years later I started reading
the ISO C standard and realized that much of what I knew was wrong. I had a _"
wow, so _that's* how it actually is"* moment on what seemed like every page.
It's not that the K&R2 explicitly teaches wrong things---obviously not;
rather, it misguides the inexperienced by _omission_. You're expected to be an
expert programmer who reads between the lines, asks the right questions about
the limitations of constructs and consults a reference manual or standard to
have them answered. The book is also not a tutorial on programming, either.

Thus if you're a n00b, you will not learn programming from K&R2 and you will
not learn C properly. A combination of K&R2 together with Andrew Koenig's _C
Traps and Pitfalls_ might be better. If you have those two books, plus the
Harbison and Steele reference manual and a PDF of a draft standard, you're in
very good shape as far as being well-informed. You still don't have a great
tutorial though.

------
fsk
One approach: Pick a simple project that you completed in a language you know.
Now try to do it in C.

C isn't good for CRUD webapp type stuff, though. For example, if you tried to
write a C program that processes a GET request, does a database lookup, and
then serves a webpage, that's going to be a big effort. (There are some
libraries out there that make this easier.)

Some important points:

\- learn about declaring the types of your variables, a big difference
compared with scripting languages

\- learn about compiling vs interpeting

\- learn about memory management and pointers (Higher level languages use
references. The implementation of references is in C with pointers.)

\- learn the common C standard libraries (stdio, stdlib)

------
dugword
Head First C by O'Reilly was pretty good. Shows how to use make and explains
linked libraries in addition to just C semantics.

------
tekknolagi
I am currently writing a small "Intro to Programming" textbook that uses C. If
you email me (username @ gmail.com), I can send you what I have right now,
along with updates.

------
throwaway000002
Perhaps this excellent looking free resource, which I haven't closely looked
at: Modern C.

It was discussed here [1], and also more recently submitted [2].

[1]
[https://news.ycombinator.com/item?id=9018247](https://news.ycombinator.com/item?id=9018247)

[2]
[https://news.ycombinator.com/item?id=9647257](https://news.ycombinator.com/item?id=9647257)

------
agumonkey
Allow me to ask, any book unrelated to C that made you appreciate, understand
and write better C in the end ? e.g a book on Pascal, or Forth, or even
something more Mathematical ?

