Path: news.demon.co.uk!dispatch.news.demon.net!demon!news.bbnplanet.com!cam-news-hub1.bbnplanet.com!howland.erols.net!portc02.blue.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: C tutorial begins January 1st
Date: 29 Dec 1996 21:10:46 GMT
Organization: AOL http://www.aol.com
Lines: 14
Message-ID: <19961229210900.QAA18421@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com

Here is your chance to learn C!

Starting January 1st I will be posting lessons on about a biweekly basis
on the C programming language.  I will be concentrating on the basics of
ANSI C, and will move on to Atari specific subjects if there is interest.

I will be using Laser C, but I don't think there will be many compiler
specific issues.  Nevertheless, I will help anyone who so desires, locate
a copy of Laser C...

I plan on going over the basics for about 15 lessons, give or take, and
then I will see what kind of interest there is in continuing.

-- Robert Dupuy
.
Path: news.demon.co.uk!dispatch.news.demon.net!demon!news.bbnplanet.com!cam-news-hub1.bbnplanet.com!howland.erols.net!news-peer.gsl.net!news.gsl.net!portc01.blue.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: Intro. to C tutorial, part 1
Date: 30 Dec 1996 17:47:14 GMT
Organization: AOL http://www.aol.com
Lines: 42
Message-ID: <19961230174500.MAA13314@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com

Welcome to the C programming tutorial!

This is the introduction to a continuing series.  I have two specific
goals for this series: to teach the C programming language and to
demonstrate its use on Atari compatible computers.  That is, to teach the
constructs of C, which is portable accross a wide variety of platforms,
and to demonstrate its use by creating real world applications for the
Atari compatible.

--What is C?  What is C++?

C has been around for a long time, but it was during the heydey of Atari,
Amiga, and Macintosh when C really came into its own as the language of
choice for developing applications.   C's popularity is due to three key
points.  One, C is a structured language.  That is, a C application can be
broken down into smaller, more maneagable segments that can be written and
tested seperately from the application as a whole.  Two, C is portable. 
That is most of the code you write for your Atari application can be
reused in applications that you may write for a different platform, like
the pc.  Only machine specific routines need to be rewritten.  Thirdly, C
programs tend to run faster than other languages.

C++ is in some respects an entirely different language than C.  Over the
years, however C and C++ have melded in function.  You must know C to
understand C++.  Some people  learning C++ learn C at the same time,
however it is wise to learn C first, and thoroughly before moving on to
C++.  C++ is an object oriented programming (OOP) language.

--Should I learn C or BASIC first?

The fundamentals of programming, i.e. accepting input, manipulating data,
formatting output, are universal regardless of which language you choose
and learning any language will help you develop analytical skills that you
will find useful in other environments.  There are versions of BASIC
available free for the Atari computer, whereas C usually costs money.  It
may be wise to start programming in BASIC to see how well you like
programming, although C compilers are pretty inexpensive nowadays.  C has
the advantage of being far more portable, should you choose to develop
programs for other environments.  I believe there is a version of BASIC
called STOS available for free download. 
(www.airtime.co.uk/users/stosser)

.
Path: news.demon.co.uk!dispatch.news.demon.net!demon!news.bbnplanet.com!cam-news-hub1.bbnplanet.com!howland.erols.net!cliffs.rs.itd.umich.edu!portc01.blue.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: Intro. to C tutorial, part 2
Date: 30 Dec 1996 17:49:03 GMT
Organization: AOL http://www.aol.com
Lines: 40
Message-ID: <19961230174700.MAA13355@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com

--OK, I want to learn C.  What do I need?

You'll need an Atari compatible computer.  That is any Atari made ST or
TT, or Falcon, or a clone.  There are clones such as the Medusa
(www.compdirect.com) and the C-LAB Falcon (www.ataricentral.com).  Or you
can have a pc outfitted with an emulator, such as gemulator 96
(www.emulators.com).  In addition you will need a C compiler.  I will be
using Megamax's Laser C.  You can't go wrong with this compiler and I will
sell you one for $40US + shipping if you cannot find one elsewhere.
(Email: RDupuy5596@aol.com)

A printer would be a great help, although not mandatory.  In addition you
may wish to purchase additional reference material.  Some great reference
books are available from Bravo Sierra
Computers.(www.teleport.com/~bensmith/bscomputrs.shtml)

--What is this 'compiler' that you are talking about?

C is a structured language,  applications are built from many smaller
segments.  Many of these segments are prewritten.  A compiler contains
libraries of prewritten program segments for use in your own programs.  A
compiler will link these segments together to create the final
application.  In addition, a compiler will check your code for syntax
errors (typos and other mistakes).  The compiler will make the final
executable so anyone, even someone who doesn't own C, can run your
programs!


--I'm still confused.  Is there any hope for me?

Probably not, but don't despair. :-)  Starting on January 1st, and about
every two weeks thereafter I will post a lesson.  Depending upon the
response, I will attempt to answer any question you may have.  Please post
to the group and don't Email me individually.  This is because, one,
someone else may have the same question and, two, someone else may have
the answer!



----Robert Dupuy
.
Path: news.demon.co.uk!dispatch.news.demon.net!demon!news.bbnplanet.com!cam-news-hub1.bbnplanet.com!news.mathworks.com!news-peer.gsl.net!news.gsl.net!portc01.blue.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: C Tutorial, Lesson 1
Date: 30 Dec 1996 20:53:03 GMT
Organization: AOL http://www.aol.com
Lines: 64
Message-ID: <19961230205100.PAA17929@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com

LESSON ONE - Get To Know Your Compiler.

If you'll recall from the introduction, the compiler is central to making
a C application.  The compiler translates the english-like syntax of your
program into a binary (1's and 0's) that the computer can execute.
In addition, since most C programs are broken into several segments, the
compiler will link these segments together and will do some rudimentary
error checking.

There are two types of compilers available: those that use and IDE
(integrated development environment) and command line compilers.  Megamax
LaserC (which is the primary compiler for this tutorial) is a good example
of an IDE compiler.  In an IDE environment, the editor (used for typing in
the C programs) and other functions are built in a easy to use shell. 
Command line compilers tend to be a little more cryptic.  With a command
line compiler you use any text editor or word processor to write your
code.  Error checking is harder to do with command line compilers, and you
may have to learn and understand how to use scripts to keep track of
various modules.  Alcyon C that comes with the Atari Developers Kit is an
example of a command line compiler.  I highly recommend that you do not
use a command line compiler to learn C.  

The goal of this lesson is to familiarize yourself with how your compiler
works and you will type in your first C program.  It will not be necessary
to understand this program, only to type it in EXACTLY as written, and to
compile it.

First, if you have not done so already install Laser C.  (or whatever
compiler you are using).  Refer to your documentation for help.  If you
still cannot install your compiler then post to this group and someone
will help you out.

Double click on the Laser C icon.  This will load the Shell and ram
resident programs.  If you will be using a command line compiler then load
a text editor.    Select the File menu, then select New.  In the window
type the following EXACTLY (case is important):

#include <stdio.h>

main() {
        printf("My first program\n");
        getchar();
             }


OK, now select the file menu again, and then select Save As.    Save this
file as First.C....

The file should now be saved to disk, you may change the name but be sure
that it has the ".C" extension, this is necessary for your compiler to
recognize it as a C program..  In Laser C, you may now pull down the
Execute menu and select run.  If you did not type any errors then Laser C
will automatically compile and run the program.  Hit return to exit the
program.  Now exit Laser C, you will find a program called First.prg on
your disk.  You may run the program again, if you'd like, just double
click on it!  (Remember to hit return to exit this program) 

If you are using a command line compiler, please refer to the
documentation.  Command line compilers usually work by typing the name of
the compiler followed by the program you wish to compile.  Also there may
be many options and several passes necessary to make them work.  Please
post to this group if you have questions about using your command line
compiler.

.

                    ----------------------------------------                    

Path: news.demon.co.uk!dispatch.news.demon.net!demon!news.sprintlink.net!news-peer.sprintlink.net!howland.erols.net!feed1.news.erols.com!insync!news.hal-pc.org!conchbbs!7861!john.kormylo
From: John.Kormylo@7861.conchbbs.com (John Kormylo)
Newsgroups: comp.sys.atari.programmer
Subject: C Tutorial, Lesson 1
Date: 01 Jan 97 04:05:04
Organization: Houston Area League of PC Users
Lines: 16
Message-ID: <861_9612311538@conchbbs.com>
NNTP-Posting-Host: conchbbs.com
X-FTN-To: rdupuy5596@aol.com

For Pure C, you will first need to specify a Project File.  Use the
DEFAULT.PRJ file provided (use the Project/Select... menu item).

You might also need to specify the default directories where the
headers and object libraries are located.  I believe it works OK
straight out of the box, though.



___ Mountain Reader II - #00000053
--
|Fidonet:  John Kormylo 1:106/7861
|Internet: John.Kormylo@7861.conchbbs.com
|
| Standard disclaimer: The views of this user are strictly his own.

.
Path: news.demon.co.uk!dispatch.news.demon.net!demon!cam-news-hub1.bbnplanet.com!news.bbnplanet.com!cpk-news-hub1.bbnplanet.com!portc02.blue.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: C Tutorial, Lesson 1, Extra Credit
Date: 30 Dec 1996 20:55:06 GMT
Organization: AOL http://www.aol.com
Lines: 44
Message-ID: <19961230205300.PAA17974@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com

EXTRA CREDIT

OK, you may add comments to any program by using the following format:

/* put comments here */

Got that?  You type (without the quotes) "/*" to start a comment and a
"*/" to end the comment.

The "/*" tells the compiler to ignore all text and the "*/" tells the
compiler to stop ignoring text.  Comments don't change the way your final
program runs or the size of your final program in anyway, but they are
usefull for making your long programs readable by other programmers or
yourself.   Here is the first.c, this time with comments


/* 
This is my very first program
*/

#include <stdio.h>  /* This is a header file.  Header file's have the '.h'
extension */

/* Every C program has a function called 'Main' */

main() {
         printf("My first program\n");  /*print my first program */
         getchar();  /* Wait for return */
              }

Of course in real life, you would not use this many comments.  Comments
that only state the obvious detract from readability and our goal is to
make our code as readable as possible!

OK, compile this program, its exactly the same as the first!  See, I told
you....

Thats it for lesson one, in the next lesson we'll go over the format of C
programs and what functions are all about.

p.s. always remember to end a comment with the '*/'  .  Its a common
mistake to just start a new line without ending the comment.  The compiler
ignores all text untill it reaches a '*/' so if you leave one out, the
compiler will ignore the rest of the program
.
Path: news.demon.co.uk!dispatch.news.demon.net!demon!news.bbnplanet.com!cpk-news-hub1.bbnplanet.com!news-peer.gsl.net!news.gsl.net!portc01.blue.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: C Tutorial, Lesson 2
Date: 31 Dec 1996 04:01:44 GMT
Organization: AOL http://www.aol.com
Lines: 105
Message-ID: <19961231040000.XAA29215@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com

LESSON 2 - elements of a C program

OK, I'm going to keep things as simple as I can here.

Some elements of a C program are requirements that must be followed in
order to allow your compiler to work.  Other elements are by tradition or
for readability and are not absolute design requirements.  

Lets examine another sample program, its not necessary to understand
everything about it at this time:

/* Count.C             */
/* This program will
   count to 10 and 
   display the output  */

#include <stdio.h>  /* This header file defines printf()  */

main() {
     int count;

     for (count=1; count<11; count++)
         
         printf("\ncount=%d", count);
         getchar();
     }


-------------------------------------------

/* Count.C             */
/* This program will
   count to 10 and 
   display the output  */

A program starts with a comment that gives the filename and brief
description of the program.
If you'll remember from lesson one, comments are simply remarks that are
ignored by the compiler, but are useful reminders that aid other
programmers in their understanding of your code.  A remark begins (without
the quotes) with a '/*'   and must end with a '*/'


#include <stdio.h>  /* This header file defines printf()  */

The next portion of a C program is the preprocessor directives.  These 
are #include and #define.    The preprocessor directives are for the
benefit
of the C compiler.  The #include <stdio.h> tells the compiler that you
will be
using the stdio.h header file.  This header file contains information
about the printf() function.  Confusing?  Don't worry I'm just trying to
give you an outline of a C program, we will cover header files again.


main() {


Remember, C is a structured language.  That means you reuse code.  over
and over.
Unlike languages such as BASIC, there are very few keywords in C.  C is a
language
made up almost entirely of functions.  Every C program contains a main()
function,
and by tradition main() goes first.  Our example only has one function,
but in real life
C programs have many.


     int count;

Initializes a variable 'count' and tells the compiler that it will be an
integer.

     for (count=1; count<11; count++)

A for loop, don't worry about this just yet.

         printf("\ncount=%d", count);

printf() is not a keyword!  printf() is a function that is being called. 
We do not have to
rewrite this function because it has already been written.  The printf()
is in the header
file stdio.h which we told the compiler to use at the beginning of the
program.

         getchar();   /* waits for the enter key before exiting */

getchar() is another function that is part of the stdio.h file.


     }

Clear as mud now?  Don't worry, I just wanted to familiarize you with the
makeup of a C program.
To Summarize:  Start with some comments so you can remember what the
program is all about later, then you will do some preprocessor directives,
such as telling the compiler what header files you will be calling up in
your program (what prewritten routines you will be borrowing), then you
will write the function main() which contains the logic of your program. 
Finally, you write any functions that
main() calls, but are not included in any header files(not necessary in
this tiny example, but done in real life)

.
Path: news.demon.co.uk!dispatch.news.demon.net!demon!news.bbnplanet.com!cam-news-hub1.bbnplanet.com!howland.erols.net!cliffs.rs.itd.umich.edu!portc01.blue.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: C Tutorial, Lesson 3 1 of 4
Date: 31 Dec 1996 23:27:23 GMT
Organization: AOL http://www.aol.com
Lines: 34
Message-ID: <19961231232500.SAA24109@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com

LESSON 3 - printf()

First, a personal aside.

I am using America Online to connect to the internet and anything that I
try to post longer than a page will cause a disconnect, so I am going to
have to keep splitting up these lessons.  Which means, inevitably someone
will find themselves missing a part.  In addition, some newsgroup servers
are so pressed for space that some articles do not last very long.  If you
need a repost..let me know.

Also, I realize that the example C programs that I have use probably still
look like a bunch of gibberish, but don't let that get you down.  Like any
language things will become more and more familiar to you in time, untill
eventually you will wonder why you ever thought it was hard.

I thought long and hard about what the lesson plan should be today.  Its a
common fault of most tutorials to get bogged down with text formattting
issues.  Text formatting is great for understanding legacy applications,
but not necessarily as important for programming a GUI (Graphical User
Interface) environment like GEM.

Nevertheless, the GEM AES (Application Environment Services) will have to
wait for more advanced lessons.  So lets tackle printf() now, so we can
begin programming today and so we can use it to display output as we
continue learning the syntax of the C language.

As I mentioned in earlier lessons, printf() is not a C keyword, but a
prewritten piece of code which is contained in virtually every C library. 
To be precise, it is contained in the header file stdio.h. (STanDard
Input/Output)  It is an output function.

(End part 1 of 4)

.
Path: news.demon.co.uk!dispatch.news.demon.net!demon!news.bbnplanet.com!cpk-news-hub1.bbnplanet.com!news-peer.gsl.net!news.gsl.net!portc01.blue.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: C Tutorial, Lesson 3 part 2 of 4
Date: 31 Dec 1996 23:28:27 GMT
Organization: AOL http://www.aol.com
Lines: 36
Message-ID: <19961231232700.SAA24162@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com

--How do I recognize a function?

Good question.  Every function from the main() function to the most
obscure is always the functions name followed by a set of parenthesees. 
Sometimes there is information inside the parentheseees, such as:

printf("Print this");

the information in the parenthesees is passed to the function.  In later
lessons, we will cover in greater detail how information is passed to and
from functions.  For now, just remember when you use printf() you are
calling a function, and information you place between the parentheseees is
information you are passing to this function, which it will interpret and
use to display information on your screen.

In the above example we are passing one argument.  This arguement is the
STRING CONSTANT "Print this"...we can pass more than one arguement to
printf().  Consider the following example:

printf("My name is: %s","Robert");

within a C program, this would display:

My name is Robert

Why?  Because %s is a FORMAT SPECIFIER.  This tells printf() where to put
a value and what kind of value to expect.  %s tells it to look for a
string.  In this example the string is "Robert"

Lets take a look at another format specifier.

printf("I make %d per week",250);

This would display

I make 250 per week
.
Path: news.demon.co.uk!dispatch.news.demon.net!demon!news-lond.gsl.net!news.gsl.net!news-peer.gsl.net!news.gsl.net!portc01.blue.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: C Tutorial, Lesson 3, part 3 of 4
Date: 31 Dec 1996 23:30:23 GMT
Organization: AOL http://www.aol.com
Lines: 40
Message-ID: <19961231232900.SAA24244@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com

Why?  because %d is a format specifier for a decimal integer value.  It
takes whatever is on the right of the comma and plugs it into the string
on the left.  Lets combine the previous two examples.

printf("My name is %s.  I make %d per week.","Robert",250);

What would this display? 

In the above examples using format specifiers doesn't make much sense.  It
would be easier just to type out a string constant such as "My name is
Robert.  I make 250 per week"  But remember, these are just examples,
format specifiers do come in handy.  Lets take another look at that
Count.C program from Lesson 2 and see if it makes any more sense now!

/* Count.C         */
/* This program will
     count to 10 and
     display the output */

#include <stdio.h>  /* Header file where printf() is located */

main() {   

     int count;

      for (count=1; count<11; count++)

           printf("\ncount=%d",count);
           getchar();
}


If we examine the printf() function call here, we can now see that the
value of count is substituted for '%d'  We can also see a '\n' that is not
printed when we run the program.  That is because \n tells the printf() to
start a new line.  In typewriter speak, it technically does a carriage
return and a line feed.

For extra credit.  Delete the \n from the above program and recompile and
re-run it.
.
Path: news.demon.co.uk!dispatch.news.demon.net!demon!news-lond.gsl.net!news.gsl.net!news-peer.gsl.net!news.gsl.net!portc01.blue.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: C Tutorial, Lesson 3, part 4 of 4
Date: 31 Dec 1996 23:33:11 GMT
Organization: AOL http://www.aol.com
Lines: 32
Message-ID: <19961231233100.SAA24334@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com

Here is your assignment:  Using format specifiers write a program, that
states your name, age, and weight, on three lines.  Use only one printf()
call.

To help you out here is a template for your program.

/* NAMEOFPROGRAM.C */
/* THIS PROGRAM DOES SOMETHING */

#include <stdio.h>  /* You must use this preprocessor directive, because
it contains the printf() function */

main() {   /* the starting bracket tells the compiler where the main
function begins */

LOGIC GOES HERE

          getchar();   /* This waits for a return, so you have time to
read the output before the program ends */

}   /* Don't forget the ending bracket, the compiler needs to know where
the main function ends too!  */


Have you all been running into compiler errors?  I'm sure you have!  I
have!  Forgetting a quote or a semi-colon gives the compiler fits doesn't
it?  C is a very exacting language when it comes to syntax, but that is in
part why it produces such great code!

oh yes, one other thing, the compiler strips out spaces, all the
indentations are for readability and are traditional, they are not
absolutely necessary.
.
Path: news.demon.co.uk!dispatch.news.demon.net!demon!cam-news-hub1.bbnplanet.com!news.bbnplanet.com!cpk-news-hub1.bbnplanet.com!portc02.blue.aol.com!newstf02.news.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: C Tutorial, Lesson4 page 1 of 4
Date: 5 Jan 1997 02:49:26 GMT
Organization: AOL http://www.aol.com
Lines: 41
Message-ID: <19970105024700.VAA08357@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com

Lesson 4 - Variables and printf();

OK, in lesson 3, you were introduced to the world of printf().  Today, we
are going to learn about variables.  We will then demonstrate the use of
variables with printf().

Variables are a basic component of every computer program.  Variables are
used to set aside a portion of the computers memory.  This portion of
memory is then identified by an easy to remember name.  This name is
assigned when you define the variable.  I'll give you an example.  Let's
say that I added the following line to a C program:

int lives;

What I've done is told the compiler that I will be using a variable, and
that the name of this variable will be 'lives'.  Also I've told the
compiler that this variable will be an integer. (whole number)

In C you cannot use a variable unless you first define it.  This is
because the compiler needs to know exactly what type of data is going to
be stored so it can make the most efficient and logical use of memory.

In the above example 'int' told the compiler to set aside space for an
INTeger variable and that the variables name is lives.  We are now ready
to use the variable.  We can assign a value to this variable.  We could
add the following line to our C program:

lives = 4;

With this bit of code we have assigned the integer value 4 to the variable
lives.  To save some time, most compilers allow you to combine the two
example C statements into one, thus:

int lives = 4;

Another shorthand is to declare more than one variable of the same type at
once:

int month, day, year;


.
Path: news.demon.co.uk!dispatch.news.demon.net!demon!news.sprintlink.net!news-peer.sprintlink.net!howland.erols.net!news.mathworks.com!uunet!in3.uu.net!152.163.170.17!newstf01.news.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: C Tutorial, Lesson4, page 2 of 4
Date: 5 Jan 1997 09:10:20 GMT
Organization: AOL http://www.aol.com
Lines: 28
Message-ID: <19970105090800.EAA17616@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com

There are other variable types besides integer.  The following chart shows
some of the common types:
-----------

(*Chart deleted -see post named C Tutorial Chart-  sorry about not
including it here but America Online has disconnected the connection the
last 10 times I tried to send this page*)

Got all that?

For now, I recommend using 'int' when you need to use whole numbers (used
when you need to count something).  Use float when you need a measured
value.  (example :  float wage = 8.82; )  And char for character values. 
(example:  char grade = 'A'; )

Question:  Can't I just make things simple and use float all the time?  
Answer  :  No.  Because of the way variables are stored in memory, this is
not a good idea.  Use 'int' for counting.  Otherwise you will end up in
the same predicament as government statisticians...that is with 2.4
children and owning 1.5 cars.  It will become clear as you program more
and more, why using the wrong variable type can have amusing consequences.

OK, you all understood lesson 3? In lesson 3, you were introduced to
printf() and we covered two FORMAT SPECIFIERS.  They were %s and %d. 
There are many format specifiers.  There are specifiers for scientific
notation, octal, and hexadecimal, among others.  The following chart shows
four common format specifiers.  For the purpose of this tutorial I will
only introduce new format specifiers as they become necessary.  
.
Path: news.demon.co.uk!dispatch.news.demon.net!demon!news.sprintlink.net!news-peer.sprintlink.net!howland.erols.net!portc02.blue.aol.com!newstf02.news.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: C Tutorial Chart
Date: 5 Jan 1997 09:14:13 GMT
Organization: AOL http://www.aol.com
Lines: 27
Message-ID: <19970105091200.EAA17672@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com

Because of America Online, I cannot even send one full page before I get
disconnected.  So here is the chart that, otherwise, would have been on
page 2 of C Tutorial Lesson 4:

-----------

Variable type     |  Keyword   |  Memory Useage  |  Use

integer           |   int      |  2 bytes        | Whole numbers
                                                 | -32,768 to
                                                 | +32,768

long integer      |   long     |  4 bytes        | Whole numbers
                                                 | -2,147,483,648 to
                                                 | +2,147,483,648

floating point    |  float     |  4 bytes        | Measured values
                                                 | +/- 10E38
                                                 | 6 digits of precision

double float      |  double    |  8 bytes        | Measured values
                                                 | +/- 10E308
                                                 |15 digits of precision

character         |  char      |  1 byte         | non numeric values
                                                 | -128 to 127

.
Path: news.demon.co.uk!dispatch.news.demon.net!demon!uknet!usenet1.news.uk.psi.net!uknet!EU.net!howland.erols.net!portc02.blue.aol.com!newstf02.news.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: C Tutorial, Lesson 4, page 3 of 4
Date: 5 Jan 1997 08:32:54 GMT
Organization: AOL http://www.aol.com
Lines: 48
Message-ID: <19970105083100.DAA17033@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com


Format Specifier   |    Use

%c                 |    single character
%s                 |    string
%d                 |    signed decimal integer
%f                 |    floating point in decimal notation

Got all that?
 
Lets put what we've learned together with a program.   

Project:  Write a program that uses variables to hold information about
the number pi and the number of sides of a triangle.
Answer:

/* Lesson4.C */
/* This program demonstrates the use of variables and format specifiers */

#include <stdio.h>

main() {

     int sides;
     float pi;

     sides = 3 ;
     pi = 3.14 ;

     printf("\nThe value of pi is: %f",pi);
     printf("\nA triangle has %d sides.",sides);

     getchar();
    }


When you run this program, pi is displayed as 3.140000!  That is not
correct of course, but without anyfurther information printf() assumes
that a float value should be displayed to six digits of precision.  We can
correct this problem by either defining pi to six digits or by providing
printf() some additional information which will tell it to display the
variable to only t digits of precision.  Try the following
line of code:

printf("\nThe value of pi is: %.2f",pi);

The ".2" tells printf() to only display two digits after the decimal
point.
.
Path: news.demon.co.uk!dispatch.news.demon.net!demon!news.bbnplanet.com!cpk-news-hub1.bbnplanet.com!worldnet.att.net!feed1.news.erols.com!howland.erols.net!portc02.blue.aol.com!audrey01.news.aol.com!not-for-mail
From: rdupuy5596@aol.com (RDupuy5596)
Newsgroups: comp.sys.atari.programmer
Subject: C Tutorial, Lesson 4, page 4 of 4
Date: 5 Jan 1997 08:35:30 GMT
Organization: AOL http://www.aol.com
Lines: 25
Message-ID: <19970105083300.DAA17101@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
X-Admin: news@aol.com



That does it for this lesson.  I'm sure you all still have some questions.
 For example:  what happens if you mismatch format specifiers?  The answer
is C will do its best to interpret the variable in the format you
requested.  Try experimenting with the format specifiers in the above
program to see what happens.  Another question you probably have is: why
are character values stored with whole digit numbers from -128 to 127. 
The answer is that the numbers correlate to letters using a lookup table. 
Try adding the following code to the above program:

printf("\n %c%c",72,73);

In the above line of code I didn't give printf() a character that the
format specifier %c calls for.  Instead I gave it a whole number. 
Printf() will not display the number, but instead display the character
the corresponds to it!

OK, we've covered a lot of ground in this lesson and there are bound to be
many questions generated.  Please post to this newsgroup with your
questions.  I am going to pause for a week and give everyone time to
digest the material.  

NEXT LESSON:  The next lesson will be posted January 11th and will cover
operators.
.
