Every time I program in C, I marvel at how clever the language is ... yet at the same time I curse some of the devices that are used to perform certain actions, which make the code that much more of a 'puzzle' to right.
I've finished a 2 day
C Programming course today ... and written a whole raft of new examples as I did so; the elegates gain so much more from seeing HOW I achieve the results as well as just seeing the results themselves. So I give you:
• Loops and conditionals - throwing a die until you get a six, then printing out the sum / average of all the throws
[source]
• A program to head in your height and weight (in once file) and call functions in another to calculate your BMI and also to return a comment about your health.
[source] and
[source]
• The significance of call by value v call by name. If you call a function and pass it a COPY of the data, then no matter how much it changes the copy, it won't effect the original. But if you pass in a POINTER so that the function works ont he same data, then it CAN change it. Which is best? Both have their uses - it's a case of horses for courses. Examples -
[source] and
[source].
• Summing numbers typed in on the command line
[source]
• How to pass an array to a function in C
[source]
• Passing pointers into functions in order to allow the function to return multiple values
[source]
• The difference between the . and the -> operator when used to access a member of a structure or union in C
[source]
• Reading data from a file, tokenising each line into a structure and storing those structures in an array
[source]
• Examples of the #define and #include pre-processor directives for setting up compile time constants and including a file of headers within multiple source files.
[source] and
[source]
• How do you read a file of unknown length in C and store it in memory, when you have to give you arrays a fixed size? You use the realloc function. This example shows you how to do it, setting up a block of memory which is expanded to take however much data you have in the file
[source] (written 2009-01-20)
26eb
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
C050 - C and C based languages - C - General [3129] Extra courses - C and C++ - (2011-01-12)
[3053] Make - automating the commands for building and installing - (2010-11-16)
[2848] C course - final course example puts it all together - (2010-07-02)
[2763] Our C and C++ training course are on Open Source platforms - (2010-05-13)
[2669] Efficient use of dynamic memory - C and realloc - (2010-03-10)
[2536] All the Cs ... and Java too - (2009-12-13)
[2504] Learning to program in ... - (2009-11-15)
[2091] C, C++ and C# ... Java and JavaScript - (2009-03-20)
[2086] C Programming v Learning to Program in C. Which course? - (2009-03-17)
C203 - C and C based languages - Conditionals and Loops [3397] Does a for loop evaluate its end condition once, or on every iteration? - (2011-08-18)
[3384] Loops - a comparison of goto, while and for - (2011-08-10)
[3243] Breaking the running sequence - an introduction to conditional statements and loops - (2011-04-11)
[3200] How a for loop works Java, Perl and other languages - (2011-03-12)
[3121] New year, new C Course - (2011-01-05)
[3004] Increment operators for counting - Perl, PHP, C and others - (2010-10-18)
[2570] Function Prototypes in C - (2010-01-11)
[1696] Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04)
[1582] Ruby, C, Java and more - getting out of loops - (2008-03-19)
[1220] for loop - how it works (Perl, PHP, Java, C, etc) - (2007-06-06)
[1191] Smart English Output - via PHP and Perl ? : operator - (2007-05-18)
[962] Breaking a loop - Ruby and other languages - (2006-12-03)
[353] Wimbledon Neck - (2005-06-20)
C210 - C and C based languages - File Handling [3386] Adding the pieces together to make a complete language - C - (2011-08-11)
[3122] When is a program complete? - (2011-01-06)
[2572] The what and why of C pointers - (2010-01-13)
[2571] Reading and writing files in C - (2010-01-12)
C205 - C and C based languages - Arrays [3245] Collections in C and C++ - arrays, vectors and heap memory blocks - (2011-04-12)
[3144] Setting up arrays in C - fixed size at compile time, or dynamic - (2011-01-24)
[3118] Arrays of arrays - or 2D arrays. How to program tables. - (2011-01-02)
[2840] Just pass a pointer - do not duplicate the data - (2010-06-30)
[1614] When an array is not an array - (2008-04-17)
Some other Articles
ContrastVariables and pointers and references - C and C++Variable Scope in C++Discount Training Courses - PHP, Perl, PythonNew C Examples - pointers, realloc, structs and moreI have not programmed before, and need to learn2000th article - Remember the background and basicsHow low can you sink?Text on a background imageTravelling to a course - station pickups