5

I'm interested in learning C. I have read K & R, and I have even done some simple C extension work in R and Python. What's a worthwhile project idea for doing something more substantial with C? Any good online resources, similar to Dive Into Python? In particular, resources focused on programmers that already know newer languages who are trying to learn C (that mention things like "Asking an array for its length is nonsense in C, you lazy Pythonista").

My background:

Math/stats, day to day programming in Python, R, mostly around natural-language-processing, algorithms, and the like.

Kirill Kobelev
  • 10,252
  • 6
  • 30
  • 51
Gregg Lind
  • 20,690
  • 15
  • 67
  • 81
  • possible duplicate of [What is the best way to learn C? What next after K&R?](http://stackoverflow.com/questions/133607/what-is-the-best-way-to-learn-c-what-next-after-kr) – Mateen Ulhaq Feb 05 '12 at 21:26
  • As noted in my accepted (first) answer from 3.5 years ago :) – Gregg Lind Apr 03 '12 at 14:49
  • Expert C programming by Peter Van Der Linden is quite good and funny. It's been written in 1994, but it's still perfectly current. – theprole Sep 28 '15 at 09:33

8 Answers8

15

Several years back, a friend of mine asked me that same question: "How do I learn C?" I told him to write a device driver.

Imagine my surprise when he actually did it.

Robert S.
  • 25,266
  • 14
  • 84
  • 116
7

Have a look at After K&R what book to use to learn programming in plain C?

Community
  • 1
  • 1
Bob King
  • 25,372
  • 6
  • 54
  • 66
  • Okay, now I'm totally embarrassed. SO's search engine totally failed me! Thanks for the smack with the clue stick. – Gregg Lind Oct 08 '08 at 20:45
4

Somewhat off topic, but since you mention your background is in Math and Stats your should try your hand at Project Euler. There are over 200 math/stat related problems available to solve. In addition, once you arrive at a solution, you can view the problem forum to see how others solved the same solution. Very handy for seeing how others solve the problem... and fun to boot!

www.projecteuler.net

Inisheer
  • 20,376
  • 9
  • 50
  • 82
  • I finally started doing these, and they are fun! It would be nice if they had a solutions archive by language (for when you solve the problem), in addition to the forum. – Gregg Lind Oct 23 '08 at 14:51
  • I got hooked on it a while back. Although I am not even close to solving them all, it does present a great challange when I have some free time. – Inisheer Oct 24 '08 at 19:50
4

I have a similar background to you. I use Python to do a lot of math and data analysis for my PhD research, and also for web programming. The difference is that I learned C first, way back in the 90s.

If you can write C extensions for Python, then I'd say you have a pretty good handle on what C is good for. In my opinion, C today is best-suited for two things:

  • Writing low-level software that interacts with hardware.
  • Writing code that does repetitive, tedious, CPU-intensive stuff (math, XML parsing, etc.)... perhaps as an extension for a higher-level language.

Of course a lot of higher-level applications are also written in C, especially under Linux I've found, but in large part these aren't really written in the "bare-bones" C of K&R or the standard library. Rather, they use frameworks like Glib, or wxWindows, or the Apache Portable Runtime, or others, which all put use some kind of object-oriented structure or conventions, and often abstract away some of the basic memory-management details of C.

So I think that making your C skills useful in today's programming language environment is largely about doing low-level work, or becoming familiar with one of these higher-level frameworks. I personally like the Glib and GTK libraries a lot, since they use a very dynamic object-oriented model (a lot like Python) without preventing you from using the low-level features of C.

Dan Lenski
  • 76,929
  • 13
  • 76
  • 124
  • Thanks for the advice Dan. I find my lack of C-fu hurts me worst when I have some program written in C that I'm trying to adapt into an extension. Maybe it's just scientific / academic programmers, but I find that those programs have the most confusing C around. – Gregg Lind Oct 09 '08 at 12:42
  • Yeah, a lot of programs written to solve a specific academic task are terribly written... they're very narrowly and hurriedly cobbled together, even if the algorithms and goals are brilliant. I know I'm as guilty as the next guy in that regard :-/ – Dan Lenski Oct 10 '08 at 03:33
2

You could write an interpreter for a simple language. Use flex/bison. Make it multithreaded etc. This is fun and tends to exercise pointers a lot. I wrote something like that for a school project: A simple stack based language with two different garbage collectors, TwoSpace and a concurrent version. That was fun. And doable as a first ever c program bigger than "hello, world"!

Daren Thomas
  • 67,947
  • 40
  • 154
  • 200
1

check out learn C the hard way, it's a free ebook which takes you through many examples of C code and exercises in order for you to learn.

http://c.learncodethehardway.org/

theprole
  • 2,274
  • 23
  • 25
0

Find or define a problem in your day-to-day work and force yourself to solve it using C instead of Python. That will force you to learn the language while keeping the problem relevent to what you normally do.

ctacke
  • 66,480
  • 18
  • 94
  • 155
  • I think this is good general advice, but for me, I think would be pretty counter-productive, since I use high-level languages for a reason in my day to day work :) – Gregg Lind Oct 08 '08 at 20:47
  • Yeah, this is the big problem with C nowadays :) It is still useful to understand and crucial to use for certain things... but most likely you will be more productive if you use something lese more of the time. – Dan Lenski Oct 10 '08 at 03:34
0

Implement a virtual machine (the JVM, for example).

JesperE
  • 63,317
  • 21
  • 138
  • 197