Real-life C application to show at introductory course?

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.

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->pointsi.

X - dest->pointsi. 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 Jun 4 '09 at 11:40 1 @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.

– anon Jun 4 '09 at 11:57.

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

2 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. – anon Jun 3 '09 at 8:30 1 @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 Jun 3 '09 at 9:47.

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.

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

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.

Might be a bit highbrow for an introductory course. – Martin Clarke Jun 3 '09 at 7:57.

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.

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?

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.

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).

The problems are interesting mostly not from being practical but rather from theoretical/educational point of view. The soultions could count as some major part of some real-life program/system but still they are not real-life programs. – lispmachine Jun 3 '09 at 8:52.

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. 99-bottles-of-beer.net/language-c-820.ht... and then follow up with anything what Neil Butterworth and Bastien Léonard above recommended :).

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).

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

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.

– lispmachine Jun 3 '09 at 13:58 The source code is unfortunately not open source. – Magnus Skog Jun 3 '09 at 15:12.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions