/************************************************************************
 *                                                                      *
 *               More Examples of Using "printf"                        *
 *               ===============================                        *
 *                                                                      *
 *          Copyright © 1993 by Mark Little, All Rights Reserved        *
 *                                                                      *
 * This source and program are provided as part of the OZAmiga Cover    *
 * Disk and may not be used in any other publication or training course *
 * without the written permission of the Editor.                        *
 *                                                                      *
 ************************************************************************
 *                                                                      *
 * Function                                                             *
 * ========                                                             *
 *                                                                      *
 * This program demonstrates some other features of the printf command  *
 * It also highlights that you must take care with this function or you *
 * can get unexpected results.                                          *
 *                                                                      *
 ************************************************************************
 *                                                                      *
 * Source File:            extra.s                                      *
 * Source Version:         1.0                                          *
 * Destination File:       extra                                        *
 *                                                                      *
 * Source Computer:        Amiga 3000                                   *
 * Operating System:       AmigaDOS                                     *
 * O/S Version:            2.04                                         *
 * Compiler:               SAS C                                        *
 * Version:                6.0                                          *
 * Destination Computer:   Any Amiga                                    *
 *                                                                      *
 ************************************************************************
 *                                                                      *
 * Revision History                                                     *
 * ================                                                     *
 *                                                                      *
 * 11-Feb-93                                                            *
 * ---------                                                            *
 *                                                                      *
 *    Original Version                                                  *
 *                                                                      *
 ************************************************************************/

/************************************************************************
 *                         INCLUDE Files                                *
 ************************************************************************
 These files usually define external functions which will be called by the
 program. They can be functions supplied with the compiler, or they can
 be functions you have written. File names enclosed in angle brackets will
 be looked for along the search path, while file names enclosed in double
 quotes (") will be looked for in the current directory only.
 ************************************************************************/

#include    <stdio.h>

/************************************************************************
 *                         Definations                                  *
 ************************************************************************
 These lines define values which will be used in the program.
 *** CAUTION *** #define sets the value by TEXT SUBSTITUTION, not by
 setting a variable and this can cause problems if you are not careful.
 Later editions will deal with this problem.
 ************************************************************************/



/************************************************************************
 *                         GLOBAL Variables                             *
 ************************************************************************
 Variables defined outside of the program modules can be accessed by all
 program modules in this file and by other modules which are linked to
 this file. Variables defined inside the opening braces of a program module
 are only accessable by that module.
 ************************************************************************/

/*======================================================================*
 *                         Force a Larger WorkBench Window              *
 *======================================================================*
 *** CAUTION *** This following statements are designed for the SAS C
 compiler version 6.0 and defines the type of window to be opened if this
 program is run from WorkBench instead of the CLI. To stop this from being
 compiled by other compilers, it is enclosed in a conditional clause.
 My compiler defines __SASC_60 which means this statement will be compiled
 into the program.
 You should also remember that some compilers may produce programs which
 may crash if they are run from the WorkBench when they should be run from
 the CLI - Rebuild this program and see what happens!
 *======================================================================*/

#ifdef __SASC_60
                  char        __stdiowin[] =
                                          "CON:0/0/640/200/Learning C - ";
#endif

/*======================================================================*
 *                         Program Variables                            *
 *======================================================================*
 These statements tell the compiler what the names of the variables used
 in this program are. They also define what type of information is to be
 stored in the variables. Number is defined as an integer and is preset
 to the value 42 - For "Hitchhikers' Guide to the Galaxy" fans, "The
 meaning of Life, the Universe and everything"!
 *======================================================================*/

   int     Number = 42;

/************************************************************************
 *                         MAIN PROGRAM                                 *
 ************************************************************************
 The module named "main" is the starting point of execution. Your compiler
 may open resources such as DOS, EXEC and other libraries before main is
 called. Consult your compiler documentation for details of what it can
 do.
 ************************************************************************/

void main(void)
{

/*======================================================================*
 *                         Use the Format Strings to Change the Output  *
 *======================================================================*
 This set of print statements will output the same things but using a
 number of different format strings. This is a good guide to how the
 format strings work. If you don't understand binary (base 2 numbers),
 octal (base 8 numbers) or hexadecimal (base 16 numbers), I suggest that
 you get a book from the library on elementary computer science which will
 explain them.
 ** NOTE ** See that I use "%%" when I want "%" to show up in my output.
 If I didn't do this then it would assume the next character was a format
 character and try to replace them with a parameter.
 *======================================================================*/

   printf("Using '%%d' with %d, '%d' is the result\n\n",Number,Number);

   printf("Using '%%4d' with %d, '%4d' is the result\n\n",Number,Number);

   printf("Using '%%04d' with %d, '%04d' is the result\n\n",Number,Number);

   printf("Using '%%4o' with %d, '%4o' is the result\n",Number,Number);
   printf("\tThis is an Octal Number\n\n");

   printf("Using '%%#4o' with %d, '%#4o' is the result\n",Number,Number);
   printf("\tThis is an Octal Number\n\n");

   printf("Using '%%4x' with %d, '%4x' is the result\n",Number,Number);
   printf("\tThis is a Hexadecimal Number\n\n");

   printf("Using '%%#4x' with %d, '%#4x' is the result\n",Number,Number);
   printf("\tThis is a Hexadecimal Number\n\n");

   printf("Using '%%c' with %d, '%c' is the result\n",Number,Number);
   printf("\tThis is character 42 of the character set\n");
}


