Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2023 - 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))
Separate function file and include file [main part]
Introduction to C example from a Well House Consultants training course
More on Introduction to C [link]

This example is described in the following article(s):
   • Learning to write good programs in C and C++ - separating out repeated code - [link]

Source code: fourthmain.c Module: C101
#include <stdio.h>

/* Function prototype - this will tell this C source code what it will find
in the functions that it loads from somewhere else. Such definitions are
very typically found in the header files such as the standard one loaded above
(which contains hundreds of things!) */

#include "fourth.h"

main() {
        printf ("How long a piece of string?\n");

        float gap;
        float mn;

        float nstr;

        nstr = 1;
        gap = 6.5;

        printf ("Gap is %.2f\n",gap);

        while (nstr < 10.0) {

                /* Hide calculation is separate function which can be
                looked after by the expert who knows all about this stuff.
                At a later point, the function can go in a separate file
                and (1) be used in lots of programs and (2) carefully tested
                on its own! */

                /* the name used here IS the same name that will be used to
                define the function. BUT variable names are not shared. That
                makes sense - you don't want to call in Old Billy's code and
                find you can't use "Boris" and "Ken" as variable names as he
                has already done so! */

           mn = ohgawd(gap,nstr);

                /* P.S. Passing everything over a single interface also means
                you can be certain of what the function needs and not have any
                nasty surprises about things it gets from elsewhere! */

           printf ("If you want %4.0f strings, ",nstr);
           printf ("you need %6.2f metres\n",mn);
           nstr = nstr + 1.0;


/* Sample Run

munchkin:c grahamellis$ ./fourth
How long a piece of string?
Gap is 6.50
If you want 1 strings, you need 12.02 metres
If you want 2 strings, you need 19.84 metres
If you want 3 strings, you need 27.66 metres
If you want 4 strings, you need 35.48 metres
If you want 5 strings, you need 43.30 metres
If you want 6 strings, you need 51.12 metres
If you want 7 strings, you need 58.94 metres
If you want 8 strings, you need 66.76 metres
If you want 9 strings, you need 74.58 metres
munchkin:c grahamellis$


Learn about this subject
This module and example are covered on the following 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
Also available on on site courses for larger groups

Books covering this topic
Yes. We have over 700 books in our library. Books covering C and C++ are listed here and when you've selected a relevant book we'll link you on to Amazon to order.

Other Examples
This example comes from our "Introduction to C" training module. You'll find a description of the topic and some other closely related examples on the "Introduction to C" module index page.

Full description of the source code
You can learn more about this example on the training courses listed on this page, on which you'll be given a full set of training notes.

Many other training modules are available for download (for limited use) from our download centre under an Open Training Notes License.

Other resources
• Our Solutions centre provides a number of longer technical articles.
• Our Opentalk forum archive provides a question and answer centre.
The Horse's mouth provides a daily tip or thought.
• Further resources are available via the resources centre.
• All of these resources can be searched through through our search engine
• And there's a global index here.

Purpose of this website
This is a sample program, class demonstration or answer from a training course. It's main purpose is to provide an after-course service to customers who have attended our public private or on site courses, but the examples are made generally available under conditions described below.

Web site author
This web site is written and maintained by Well House Consultants.

Conditions of use
Past attendees on our training courses are welcome to use individual examples in the course of their programming, but must check the examples they use to ensure that they are suitable for their job. Remember that some of our examples show you how not to do things - check in your notes. Well House Consultants take no responsibility for the suitability of these example programs to customer's needs.

This program is copyright Well House Consultants Ltd. You are forbidden from using it for running your own training courses without our prior written permission. See our page on courseware provision for more details.

Any of our images within this code may NOT be reused on a public URL without our prior permission. For Bona Fide personal use, we will often grant you permission provided that you provide a link back. Commercial use on a website will incur a license fee for each image used - details on request.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2023: 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/resources/ex.php4 • PAGE BUILT: Sun Oct 11 14:50:09 2020 • BUILD SYSTEM: JelliaJamb