Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
C course - final course example puts it all together

"Yes - but how do we put all of those things together?" ... delegate question on many programming courses. As a trainer, I have to take our students through each of the main features of a language - to ensure they understand the fundamentals and perhaps more. But the it's just as important to take time before the course ends to pull all the threads together and show a complete, practical, maintainable and robust piece of code.

So here I am, on a Friday evening. Delegates have headed off to places as wide ranging as Norwich and Exeter, and I'm writing up the example that I completed just before they left. [source code link].

The example program reads one of our recent log file - they're currently around 40 Mbytes per day - and uses regular expressions to filter out all of those accesses which were arrivals from a well know search engine.

We have no way of knowing how long search strings will be, nor how many arrivals we'll have, so the memory management needs to be dynamic and use the heap ... so our example's got to include things like malloc calloc and realloc. And we have various string manipulation functions in use to find, extract and save on the heap the elements we need from each line.


Why would people use C for an application such as this? Perhaps because they knew the language already, or perhaps because they needed to run it so often and on so much material that it had to be FAST. And so you'll notice that in order to get the speed, we've compiled our regular expressions outside our main data reading loop, and we've also extended our heap memory block in chunks of 10 records at a time. The simplest coding would have been to extend the capacity one at a time, but this would have been very slow. 100 at a time would probably be better!

If you want to learn C next time I teach the course, have a look [here] if you've never programmed before and [here] if you'll be converting from another language. I'm not promising you'll be able to quickly write code like my example by the end of the course - that requires a bit more practice - but I can promise you that you'll understand what's going on, you'll be able to fathom out some previously unfathomable code, and you'll be well on the way to becoming a C programmer.

(written 2010-07-02, updated 2011-01-05)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
C212 - C and C based languages - Memory Management
  [1497] Training Season Starts again! - (2008-01-07)
  [1581] What is an lvalue? (Perl, C) - (2008-03-18)
  [1589] Dynamic Memory Allocation in C - calloc, realloc - (2008-03-22)
  [1670] Dynamic Memory Allocation in C - (2008-06-09)
  [1845] Passing a table from Lua into C - (2008-10-18)
  [2669] Efficient use of dynamic memory - C and realloc - (2010-03-10)
  [3118] Arrays of arrays - or 2D arrays. How to program tables. - (2011-01-02)
  [3144] Setting up arrays in C - fixed size at compile time, or dynamic - (2011-01-24)
  [3386] Adding the pieces together to make a complete language - C - (2011-08-11)
  [3416] Storing Tcl source code encoded, and running via your own C program - (2011-09-02)
  [4128] Allocating memory dynamically in a static language like C - (2013-06-30)
  [4340] Simple C structs - building up to full, dynamic example - (2014-12-03)
  [4634] Regression testing - via a very short C testing framework - (2016-01-29)
  [4635] Encapsulating logic in functions and structs - the C approach to Object Oriented techniques - (2016-01-30)

C050 - C and C based languages - C - General
  [2002] New C Examples - pointers, realloc, structs and more - (2009-01-20)
  [2086] C Programming v Learning to Program in C. Which course? - (2009-03-17)
  [2091] C, C++ and C# ... Java and JavaScript - (2009-03-20)
  [2504] Learning to program in ... - (2009-11-15)
  [2536] All the Cs ... and Java too - (2009-12-13)
  [2763] Our C and C++ training course are on Open Source platforms - (2010-05-13)
  [3053] Make - automating the commands for building and installing - (2010-11-16)
  [3129] Extra courses - C and C++ - (2011-01-12)
  [4335] Flexible public courses - residential or commuting, programming newcomer or experienced, C or C++ - (2014-11-30)
  [4341] Segmentation Fault, Segmentation Violation, Bus Error, Stack Smashing - (2014-12-04)
  [4434] Public training courses - upcoming dates - (2015-02-21)


Back to
Local information for Melksham Hotel Guests
Previous and next
or
Horse's mouth home
Forward to
What are C++ references? Why use them?
Some other Articles
Atworth Village Fete - on the Melksham Community Area Partnership stand
Further C++ material - view new or old
Fresh Paint for course presentation - including C++
What are C++ references? Why use them?
C course - final course example puts it all together
Local information for Melksham Hotel Guests
Catching up with an old friend
Objects and Inheritance in C++ - an easy start
Learning about Regular Expressions in C through examples
String functions in C
4759 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, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 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., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/2848_C-c ... ether.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb