Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact

Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
C and C based languages module C204
Functions, Macros and programs in multiple files
Exercises, examples and other material relating to training module C204. This topic is presented on public courses Learning to Program in C, Learning to program in C and C++, Programming in C, C and C++ Programming, Learning to program in C and C++, C and C++ Programming

Background
As your code grows from 5 to 50 to 500 lines, it becomes less managable as a single block. Functions allow code to be split into more managable blocks, which can then be saved into separate files if you like so that the same logic can be shared between a number of different programs where appropriate.
Articles and tips on this subjectupdated
3721Naming blocks of code, structures and Object Orientation - efficient coding in manageable chunks
Soon after you start to program, you'll learn that you want to re-use code. And that re-use will sometimes come in the form of loops, and at other times in the form of named blocks of code which you'll call up from multiple places in your program, or indeed from multiple programmers. • A good ...
2012-05-12
(longer)
3717Returning extra results from a function in C
There are three ways of returning a result from a function in C. You can use return to pass a result back, you can use a variable declared outside all of your function (so it's global and accessible everywhere), and you can pass in a pointer to act at the target for where a result is to be saved. If ...
2012-05-05
 
3237Using functions to keep look and feel apart from calculations - simple C example
There are a number of distinct elements in any program. • There's the look and feel of the program to the outside world - what it says as it prompts, how its forms are displayed on a web page, the formatting of the results, how it reports errors, etc. • There's the calculation bit that ...
2011-04-09
 
2841C Course exercise and sample answer - source in 2 files
Here's a sample exercise from the C course ... set yesterday to tailor the course for the particular group of delegates that we have this week: /* Complete my program ... ... in 2 files ... fixed VAT rate at compile time   Function params - cost per item (net) and no. of items at this cost   tc ...
2010-06-30
 
2575Sharing variables between files of code in C - extern
In C, If you want to share a variable between a number of functions, you can declare it at the top of your file, outside the functions. It's then an element that's held in memory all the time and available to all your functions. Since your functions are separate elements which are joined together at ...
2010-01-15
 
2570Function Prototypes in C
Programs other than the shortest are name up of named blocks of code (functions) into which parameters are passed and from which results are returned. And rather than have all the functions that make up an application in one file of source, you'll share them between several. That way, maintainable ...
2010-01-13
 
1478Some new C programming examples - files, structs, unions etc
A series of new "C" examples have been added to the web site - a course for a small group allowed me to go somewhat away from the more normal run yesterday and write some new illustrations in front of them. Call by value v call by pointer comparison: link Using extern to share a variable between two ...
2007-12-19
 
1163A better alternative to cutting and pasting code
If you're new to coding, you'll be so concerned to be writing code that works that you may not take a look at coding technique. Your nose will be so close to the grindstone as you work that you won't take the time to look and ask "Do I need to keep grinding anyway?" If you find yourself writing a piece ...
2007-04-26
 
775Do not duplicate your code
If you've writing or maintaining a program and you find yourself cutting and pasting a chunk of code, STOP and think again. By duplicating a block of code, you're duplicating your maintainance task from that point onwards - any fixes applied to the original much be applied to the copy too. And that's ...
2006-06-30
 
Examples from our training material
abcpointers.c   Ways of passing back results from a function
fundy.c   call by value v call by pointer / reference
funfiles.c   The home for an extern variable
funfuncs.c   use of extern to reference variable held elsewhere
healthcheck.c   function prototypes and extern
healthybits.c   functions to be loaded from another program
lp3.c   Variable declaration and scopr in inner blocks
makefile   makefile for module C204
p3.c   Returning values from a function
taxi.c   functions for VAT rate exercise
tcall.c   Function definition and call
tcmain.c   Using functions
tcsub.c   Functions in their own file
tcsub.h   Using functions - the header file
third.c   Separating look and feel from business logic
twice.c   Function names must be unique in C
twice.cpp   Two functions of same name in C++
xrcz.c   Sample answer - main code for VAT exercise
Background information
Some modules are available for download as a sample of our material or under an Open Training Notes License for free download from http://www.training-notes.co.uk.
Topics covered in this module
Defining functions.
Parameters and return values.
Exercise.
Function prototypes.
Variable scope and global variables.
Constants.
Header files and other Macros
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.

Well House Consultants specialise in training courses in Python, Perl, PHP, and MySQL. We run Private Courses throughout the UK (and beyond for longer courses), and Public Courses at our training centre in Melksham, Wiltshire, England. It's surprisingly cost effective to come on our public courses - even if you live in a different country or continent to us.

We have a technical library of over 700 books on the subjects on which we teach. These books are available for reference at our training centre. Also available is the Opentalk Forum for discussion of technical questions.


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/resources/C204.html • PAGE BUILT: Thu Sep 18 11:03:17 2014 • BUILD SYSTEM: WomanWithCat