So many good projects for studying C programming lanuage.

时间:2024-01-07 08:58:02

Some one asked a question for studying C programming language on stackexachange.com. He got a bucket of recommanded project, which I reformed here.

Reimplementing the famous library

1. the c standard library.

string.h

memchr, memcmp, memcpy, memmove, memset, strcat, strncat, strchr, strcmp, strncmp, strcoll, strcpy, strncpy, strcspn, strerror, strlen, strpbrk, strrchr, strspn, strstr, strtok, strxfrm

stdlib.h

abs, div, labs, ldiv, atof, atoi, atol, strtod, strol, bsearch, qsort

time.h

asctime, difftime

More advanced task would be to reimplement printf.

2.you have to parse a XML file at work using Java, then at home you can try rewrite the parser in C/C++.

One week homeworks or toys

  • 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.
  • Only one worth adding would be something along the lines of implementing a basic TCP stack over UDP. Since you did not hit anything networking
  • Write a raytracer. Might be a bit time-intensive, but you can choose which more advanced techniques to implement on your leisure, plus the results are eye candy if you put some work into it.
  • 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.
  • Try to make a peer to peer software... We had this as an assignement, it's fun and you'll learn tons of things with it.
  • Try writing a small lambda calculus evaluator. Initially just malloc all you memory, and don't freeanything. Later, try writing your own memorypool with a small (mark-and-sweep) garbage collector.
  • some game without GUI. 1. Address book. No gui just text. Link lists. Learned memory and sorting; 2. Fractals. Learned math mostly but good test for ADT; 3. Solitaire game. Again no gui just text; 4. Also did a black jack game.

Reimplement a old software:

I recommend that you try to write a line-oriented text-editor akin to the old MS-DOS "EDLIN" program.

See http://en.wikipedia.org/wiki/Edlin for a description of EDLIN

Online judge practices and puzzles

Facebook Puzzles

Dropbox Puzzles

Reddit Puzzle: http://blog.reddit.com/2010/08/reddit-is-hiring.html

I have not looked into this yet, but UVA Online Judge has problems and I have heard as a recommended source for something like this: http://uva.onlinejudge.org/

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

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

Hacking into some real system

The Ruby interpreter is quite a fun project to work on, actually - there's a surprising amount of both low-level and linguistic hackery that goes on in there.

Skim the Linux source code, the FreeBSD source code, the OpenBSD source code, or the LibUSB source code.Find something that grabs your "Hey, I can do better than that! reflex." DO better than that!(LibUSB needs the ability to talk to devices, like My HP All-In-One, that used an outgrowth of the Parallel Port standards that were ported to USB.)

Read and done the exercises of the book.

1.The C Programming Language by Brian W. Kernighan, Dennis M. Ritchie

Keep a copy of K&R by your side, but find something real to work on.

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.

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

3.working through code in C Interfaces and Implementations book.

4.On the other hand, if you are interested in system programming (e.g., to understand how to talk with the OS directly), there are tons of books and projects. I would recommend Unix Programming Environment,Advanced Programming in the UNIX Environment and UNIX Systems Programming: Communication, Concurrency and Threads.

5.How to implement a simple RMDB: according to this article.