views:

517

answers:

15

I am holding a course on the C programming language, and I want to show the students some real-life useful applications of C, to catch their interest. Usually all they see are boring programs, with no practical utility, so I am wondering what sort of useful applications can be presented, maybe something that they can use on their own (hopefully this will motivate them to write more C code). They are assumed to have some C knowledge by now, so they should be able to understand even more complex programs, but not too complex. And it should take at most one hour or so to present the applications.

If you have any interesting ideas, I would be more than interested to hear them.

A: 

I would suggest looking at gnu libc. There are many great examples in there which can teach a lot about systems programming and library design.

There are also many unexpected implemenations.

mikelong
Might be a bit highbrow for an introductory course.
Martin Clarke
A: 

I suggest nmap.

Geo
A: 

How about a paintbrush application written in C. Graphics would surely catch their attention. If paintbrush app is too much, maybe you can show some smaller graphic applications in C.

Rashmi Pandit
A: 

Instant Planner. I might be a bit biased in this matter, but I think it's a pretty cool program based on C. You can make quotations, draw stuff in 2D and render in 3D.

Magnus Skog
where's the source code?
lispmachine
The source code is unfortunately not open source.
Magnus Skog
A: 

If it is something for a beginners class how about something like a restaurant questionnaire. Take a couple of questions and then return a type of food to go for based on their mood ect... something a bit fun but shows input, output and some basic decision making?

Dom
+1  A: 

If they are interested about Unix, I would show them cat, ls, how the shell launches a program or redirects output, etc.

Bastien Léonard
IMHO these programs are very optimized and have unreadable code. For example cat can alloc memory without freeing it, because it's a program that is used in short-runs scenarios, and the memory will be freed as soon as application exits anyway.
@emg: I wouldn't show them the real code, I would only show an understandable example. For example, for ls I would simply show how to list directories and print permissions, I think.
Bastien Léonard
A: 

I would suggest showing them some examples from LiteratePrograms. Most articles there are not actually real-life programs, but many explain how to solve real-life problems for a C programmer.

ahy1
+1  A: 

I would use the Markov Chain example presented in Kernighan & Pike's excellent book The Practice of Programming. This uses a moderately complex data structure to generate random but meaningful (and amusing) text. The C implementation is contrasted with imnplementations in other languages. And the book is one that any aspiring programmer should read.

anon
+3  A: 

Maybe http://nehe.gamedev.net/? Programming OpenGL is one of most fun ways to use C. They sure will be interested. The page is full of examples with well written code.

Here is one example. It contains practical usages of malloc:

/* function to allocate memory for an object */
void objallocate( object *k, int n ) {    
        /* Sets points Equal To VERTEX * Number Of Vertices */
        k->points = ( vertex* )malloc( sizeof( vertex ) * n );

And also code operating on non trivial structures:

/* Calculate x, y, and z movement */
a.x = ( sour->points[i].x - dest->points[i].x ) / steps;

As well as file operations. It's quite simple, but maybe that is what you are looking for.

-1 Those are samples not real-life programs.
lispmachine
@lispmachine: depends on what you mean by real life. They sure are real life compared to e.g.: double linked list implementations showed on C courses as an introduction to data structures.
+1  A: 

How about Cheese? It's rather simple, small app, nicely written and fresh looking despite being written in plain old C.

lispmachine
A: 

Project Euler is great for a course since:

  • there are so many questions, ranging from simple to impossible
  • many of them are really smart questions
  • use bignum library (real world)
  • you can easily compose a reusable library (real world)
dfa
The problems are interesting mostly not from being practical but rather fromtheoretical/educational point of view.The soultions could count as some major part of some real-life program/systembut still they are not real-life programs.
lispmachine
A: 

Introductary you could to show them "hello world", it is maybe the most important program for any language because it gets you started in the simplest easiest way with the editor, compiler and lets you have a look at the output.

and to show complexity you can can follow up with something like this: 99 bottles of beer written in C as a Linux kernel module.

http://99-bottles-of-beer.net/language-c-820.html?PHPSESSID=8cb57d73efa08fb90354fc81f4928ffa

and then follow up with anything what Neil Butterworth and Bastien Léonard above recommended :)

Makach
A: 

Give them a unit test harness, i.e. an application which gets some flavor of unit test definitions at link-time, runs and calculates statistics.

Depending on how much work you want to put into it, this can be anywhere from very basic to vary advanced implementation (automatic test dependencies, output to different formats, dynamic or static linking of test sets and so on).

Christoffer
A: 

Second idea (in case there are not enough webcams laying around): a Jabber client Gossip.

lispmachine
+1  A: 

Anything Gtk+ or gnome -related

ZeD