tags:

views:

732

answers:

15

I have some basic knowledge of C (and a bit more of C++). I got a copy of K&R, and I want to use it to help me dig deeper into the language. What is a good idea that will involve using most of C's features and standard library? Also, what important differences between C89 and C99 should I be aware of?

EDIT: Forgot to mention, this should be mostly doable for a beginner. I'm not asking for a programming tutorial; rather, something mid-scale. I understand that OS stuff is one of C's main purposes, but wouldn't that be too complicated?

Also, reading and answering questions is always a good idea, but I want to get some actual practice, make a program that will do stuff.

+2  A: 

Depending on how deep you want to go, maybe Doom?

Jim Buck
+1 Doom is the best!
Anthony Cuozzo
+2  A: 

Hardware (embedded microprocessor system) and operating system kernel codes?

stanigator
It's great fun with mcu:s, Atmel AVR:s are nice.
Johan
PIC18F's are fun too for me.
stanigator
+10  A: 

Reading and answering C questions on StackOverflow is a good way to learn fine details of the language.

Martin v. Löwis
+1 - It worked for me!
Chris Lutz
+4  A: 

An interpreter for a simple grammar language. No lexer/parser generators should be used of course to make it interesting.

Ray
+8  A: 

I would recommend working through these: http://projecteuler.net/. Of course sometimes it helps to do some of these inefficiently in C, to get a sense of how long brute force takes. Then try to come up with a more clever way and really see the beauty of C well done!

Vince
+19  A: 

Implement a programming language. This doesn't have to be terribly hard - I did the language that must not be named - but it will force you to learn a lot of the important parts of C. If you don't want to write a lexer and/or parser yourself, you can use lex/flex and yacc/bison, but if you plan on that you might want to start with a somewhat smaller project.

Take some program you have in a higher-level language and rewrite it. If you have a Perl/Python/Ruby/Bash script that you use a lot, and you notice a lag time while it runs, rewrite it in C with a focus on performance.

It's my opinion, however, that if you're writing a program to learn C, it's better to reinvent the wheel. Programming in C is all about making and adjusting the wheel, and if you only learn C by using libraries that abstract away the wheel for you, well, you're really not learning C. It may be faster - and when you're working on a real project in C, by all means, don't reinvent the wheel - but if you're doing this to learn, then by all means, learn how the wheel works.

Chris Lutz
+1 Reinventing the wheel.
Anthony Cuozzo
Resources for this project are all found here: http://stackoverflow.com/questions/1669/learning-to-write-a-compiler
dmckee
+1  A: 

When I want to learn a new language I always come up with some utility that I would find useful and write that. I find that writing an actual program that is going to be used teaches me more than just proof of concepts.

For example, you might write a program that, starting at specified directory it will transverse down building a list of all files and do something with them. Like give you simple list of all files larger than a specified size. Then figure out how to add filters so that when complete you can use it to clean up directories. It might look for the word "backup" or files that contain tmp. Don't forget to have at least one function that passes a pointer to a pointer to get a good feel for them.

Yes, i know you can do that as a script but you can also customize to something specific to you.

Ben
A: 

For difference in languages do not wory to much. There is not lot of them, but still. (i am writing c for 2 years but still does not know what stadard is there, if i got unsuported complier it takes few minutes to fix the code)

One of most frustrating thing that can happen is usualy defining values in the middle of code like in for(int i;i<2;i++); loop which is considered only c++ specification. That was what I was confronting whit. In cross compiling you will find other thing much more frustraiting that standard difference.

For starting in c I suggest learning algorhitms and operating systems or embedded system (c in by far still most common language on low/mid end embedded systems)

Get some peace of hardware for instance from microchip, atmel or freescaleand and check for their embedded RTOS support.

ralu
`for(int i = 0; i < x; i++)` is valid in C99, but not C89, but GCC whines at you if you use it outside of C99 mode, so I don't use it.
Chris Lutz
I knew it. It never worked for me.Thanx for this.
ralu
A: 

Do some kernel hacking

sudo apt-get install git-core
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git linux-2.6

I use ubuntu, so I did an apt-get, I use gentoo too, the command there is # emerge dev-util/git

devin
A: 

The 2006 ICFP Contest problem was incredibly fun. The first part, implementing the virtual machine, is a smallish problem that's just the sort of thing C is still appropriate for. It won't teach you much of the standard library, though.

Darius Bacon
+1  A: 

My favorite program to implement in situations like this is a Regex matching program, which uses pretty basic syntax but uses a lot of the low-level features of a language (and given that C is pretty low-level language, that's most of them).

Tyler Menezes
+1  A: 

A simple database application (contact list, movies, albums, etc.) might also be a good project; it would involve file I/O, interactive I/O, memory management, reasonably meaty data structures, etc.

John Bode
A: 

Build a chess game. This can be quite trivial as you can even do it with a plain console. It gets you to implement some logic, use data structures, work with pointers, etc. Store the score so you get to work with persistency.

Rui Craveiro
A: 

Maybe see (& improve) bigfiles.c and the use of man 3 fts (traverse a file hierarchy):

http://codesnippets.joyent.com/posts/show/1888

A: 

How about http://projecteuler.net/ done with c? That should trigger some braincells :)

Johan