tags:

views:

178

answers:

6
+3  Q: 

Small C Projects

I am a professional developer who generally uses high level, memory managed languages. However, I am growing more and more ashamed at my incompetence at low level languages like C, which I haven't used since my Systems courses in college.

I want to relearn some of the more distinct parts of the C language, but I don't have a large amount of time to devote to hobby work. What are some small projects that would highlight the low level aspects of the language to help me rekindle my knowledge?

+5  A: 

In terms of simple "learn the mechanics" projects, try making a linked list. It teaches you about layered pointers and manual memory management (when you have to delete the thing).

Christian Mann
And recursion (for deletions) too! That's always a plus.
Christian Mann
+5  A: 

Buy the K&R book, do the exercises. You'll (re)learn all you need about C, and a lot about CS too. Skip to the later chapters for parsing and Unixy goodness.

Adriano Varoli Piazza
That was how I learned C - and from the first edition, in 1985. Good days.
Bob Murphy
+2  A: 

Try http://projecteuler.net, they have many nice problems.

You could also try playing with bits: http://graphics.stanford.edu/~seander/bithacks.html.

You could also implement a image or data (de)compression algorithm. It's fun, there is lot of bit twidling, pointers, trees, recursion, mathematics and place for optimizations.

ruslik
+1 for projecteuler.net this is good site to learn algorithms
nguyendat
Algorithms, but that's not really what he's looking for here. OP wants low-level stuff in C. Algorithms can be learned in any language.
Christian Mann
A: 

I was read some books in C an here is book i thinks useful for you:

  1. For basic C: The C Programming Language by Brian W. Kernighan, Dennis M. Ritchie alt text

  2. For helpful issue and tips: C Traps and Pitfalls by Andrew Koenig

alt text

Note: eBook version of 2 book available on the internet

nguyendat
+1  A: 

I would say take any problem you encounter at work and try to use lower level language to solve it. For example, if you have to parse a XML file at work using Java, then at home you can try rewrite the parser in C/C++.

Alvin
+5  A: 

Project Euler is good for learning CS math, but there's other things that might be a little more immediately practicable. Here are the most useful assignments I recall from undergrad:

  • Implement all your favorite data structures: linked list, binary search tree, binary heap, chained hash, quadratic probing hash, etc. Build a string->string dictionary as an RB tree, a treap, and a hash.
  • Write a memory allocator. Get eg a big 16mb chunk from the operating system, then write your own versions of malloc() and free() that work entirely inside that. Make sure it can handle allocations of arbitrary sizes -- not just char and int, but strings and structs. Boundary tag allocation is probably easiest. For bonus points, use this malloc() for the assignments above, to make sure it really works.
  • Count the number of occurrences of each word in the collected works of William Shakespeare. Provide functions to print these sorted in alphabetical order or by count.
  • Here is libtiff. Write a program that shrinks an input image to half its size.
  • Write your own toy filesystem. Get a big 1gb file from the OS, pretend that is a blank disk and that you are the operating system, and then write your own fopen(), fwrite(), etc.

Each of these was a one week homework assignment, iirc, with the exception of the filesystem which was a little more work.

Crashworks