Home Accessibility Courses Diary The Mouth Facebook Resources Site Map About Us Contact
When is a program complete?

Learning C and C++"Code is never completed ... it can always be improved." ... it's one of the most difficult aspects in many projects to say "yes, that does what we want and we should go for a release now rather than continuing to develop until ... until it's so late that we've missed the boat / added too much complexity to make the program useful and viable". Anyone who's managed a software project may be very familiar with this sort of decision, and how hard it is to make.

A similar thing happens with examples on our web site ... "Wouldn't it be nice if this example also showed xxx" we'll say to ourselves, or "should it also check for yyyy". But, alas, the result of adding in xxx, yyyy and zzzzz while we're at it means that the example is far less followable in showing the basic fundamental elements.

Yesterday, I recalled an example that reads a web server log file in a C program and stores pertinent elements into a growing array (via realloc) of structures. (See [source]). But the code included the opening of the log file as follows:
  fh = fopen("ac_20100630","r");
Now - that's all well and good, except that the program is fixed to a specific log file, and exited with a nasty segmentation fault if the file did not exist. Discussion ensued, and we modified the code to:
  fh = fopen(*++argv,"r");
  if (! fh) {
    printf("Oh Shdear ... no file\n");
    return (1);
    }


Better? Yes. Perfect? No! it would have been a good idea to echo out the name of the file we failed to open, give an excuse the reason, such as "no such file" or "not readable", etc ... all of which would have contributed to flannel which would render the original example far too dilute in what it intended to show.

A good approach that I've often taken is what I describe as "build up examples", where I keep a whole series of versions / snapshots showing how code has developed; here's such a series from yesterday, looking at handling the command line inputs in C which provided a very good and interesting example of handling of character strings, individual characters, and the arrangement of data into somewhat more complex layouts.
Step 1, Step 2, Step 3, Step 4

There's a further "build up" example showing the first use of structs (structures) in C ... and that's here:
Step 1, Step 2, Step 3

And even building up examples like that, we sometimes produce some interesting sideshoot examples - [here] is one that looks at the thorny issue of string comparison; written during the course, although it largely duplicates [this example] from the course.

(written 2011-01-06, updated 2011-01-08)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
C206 - C and C based languages - Character Strings
  [3718] Splitting a record into individual data values in C - (2012-05-04)
  [3593] Chars, char arrays and strings in C. Some early cautions and pitfalls. - (2012-01-26)
  [3146] Strings in C - (2011-01-25)
  [3144] Setting up arrays in C - fixed size at compile time, or dynamic - (2011-01-24)
  [2844] Learning about Regular Expressions in C through examples - (2010-06-30)
  [2843] String functions in C - (2010-06-30)
  [1338] Handling Binary data in Tcl (with a note on C) - (2007-09-09)

C209 - C and C based languages - Structures and Unions
  [3386] Adding the pieces together to make a complete language - C - (2011-08-11)
  [3145] Structures v Structure Pointers in C. How, which, why. - (2011-01-25)
  [2573] C Structs - what, how and why - (2010-01-13)
  [1669] What are Unions (C programming) - (2008-06-08)
  [1584] Using Structs and Unions together effectively in C - (2008-03-21)
  [1572] C - structs and unions, C++ classes and polymorphism - (2008-03-13)
  [1478] Some new C programming examples - files, structs, unions etc - (2007-12-19)

C210 - C and C based languages - File Handling
  [2572] The what and why of C pointers - (2010-01-13)
  [2571] Reading and writing files in C - (2010-01-12)
  [2002] New C Examples - pointers, realloc, structs and more - (2009-01-20)


Back to
New year, new C Course
Previous and next
or
Horse's mouth home
Forward to
C++ objects - some short, single file demonstrations
Some other Articles
Car Parking in Melksham - thoughts on the proposed scheme, and wider thoughts too
The family is defunct. Long live the family.
C++ - putting the language elements together into a program
C++ objects - some short, single file demonstrations
When is a program complete?
New year, new C Course
Learning to write good programs in C and C++ - separating out repeated code
TransWilts - some things to see and do
Arrays of arrays - or 2D arrays. How to program tables.
Opportunities for Melksham - new businesses in the town
4255 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3122_Whe ... lete-.html • PAGE BUILT: Sun Mar 30 15:20:58 2014 • BUILD SYSTEM: WomanWithCat