Where we are
------------
I started with two lectures on C so far.  We went through a simple C program
and discussed the difference between declaration and definition (definition
is when memory is allocated), the basice syntax, what preprocessor directives
were all about.

I have also talked about how arrays work, and very briefly introduced 
pointers.

What to cover:
--------------

I'd like you to go over how printf and scanf work.  We haven't talked about
pointers and addresses yet, so you will have to explain why we pass in the
address of variables scanf.  Please warn them that scanf is very particular
about what it will match on.  Everyone has seen regular expressions before,
so you can talk in terms of that.

Here are a few examples taken from the King book.

#include <stdio.h>

int
main()
{

        double x = 43.2892;
        double y = 5527.0;
        int i = 10;
        int j = 20;


        printf("Printing the variables correctly:\n");
        printf("i = %d, j = %d, x = %f, y = %f\n", i, j, x, y);

        printf("Printing them all as integers:\n");
        printf("i = %d, j = %d, x = %d, y = %d\n", i, j, x, y);


        printf("Printing formatting the doubles to print one decimal place:\n");
        printf("x = %.1f, y = %.1f\n", x, y);

        printf("Printing them all as doubles:\n");
        printf("i = %f, j = %f, ", i, j);
        printf("x = %f, y = %f\n",  x, y);


        printf("Giving printf too few arguments:\n");
        printf("i = %d, j = %d \n", i);


        printf("Giving printf too many arguments:\n");
        printf("i = %d\n", i, j);


}

Here's one scanf example:
You will need to explain that the result is being stored in the memory
location given by the address of the variable.

#include<stdio.h>

int
main()
{
	int i, j;
	
	/* In this example, scanf tries to match an integer until it 
	 * encounters a non-digit character. Then it skips any whitespace
	 * (including new lines) to find the beginning of the next integer.
	 * If it is unable to find a match, it returns without changing what
	 * has been read.
	 */
	printf("Enter two integers:\n");  /*e.g., "1 3", or "1\n3"
	scanf("%d%d", &i, &j);
	printf("You entered %d and %d\n", i, j);

	printf("Enter two different integers with a comma between\n");
	scanf("%d%d", &i, &j);            /*e.g., "2, 4" */
	printf("Now i = %d and j = %d\n", i, j);

	printf("Try to satisfy the scanf format \"i = %d, j = %d\"\n");
	/* If we don't put in the next new line, the following line won't
	 * match because it will see the newline from the previous scanf
	 * and that doesn't match i
	 */
	scanf("\n");
	scanf("i = %d, j = %d", &i, &j);
	printf("i = %d, j = %d\n", i, j);

	printf("Enter two ints to see what happens when we don't \n");
	printf("give a variable's address as an argument.\n");
	scanf("%d%d", i, j); /* segmentation fault*/

	return(0);

}

The bottom line with scanf is that it is very tricky to get the matching
right.  We will cover other methods of reading and parsing input later such
as fgets().


Expressions
-----------

This is the final topic which you could mention if you have time. (If you
don't it is not a problem, I'm just not sure how long it will take for
students to understand the format strings and the workings of printf.)

1. You can put assignment statements in expressions, but unless it is
 an expression in a while loop or if statement is it best avoided.

e.g.,  The following two examples are common uses of assignments in expressions.


FILE *infile; /*Don't bother explaining about the data types */
char *line;

if( (infile = fopen("testfile", 'r')) == NULL) {
	perror("Fopen:");
	exit(1);
}

while( (line = fgets(infile)) != NULL) {
	   /*process line*/
}


The next statement is also reasonably common, but should be avoided except
in simple cases, such as initializing to 0

int a, b, c;

a = b = c = 10;  /* a, b, c all get the value 10 */

watch out for

double a;
int b;

a = b = 3.3;  /*a will be 3*/


Boolean expressions:
-------------------

Students should be mostly familiar with boolean expressions except that
in Java there is a boolean type.  A comparison in C actually evaluates to an
integer value

E.g., 10 < 11 evaluates to 1
      11 < 10 evaluates to 0

(i < j < k)  is legal C, but means (i < j) < k.  (i < j) will evaluate to
0 or 1 and that value will be comapred to k.

(i < j && j < k) is the correct version of this.

When in doubt add parentheses to make it clear what the precedence should be.
