C Programming

GOOD FORM
Perhaps we should say programming style or readability. The most common complaints we would have about beginning C programmers can be summarized as,

Your programs will be quicker to write and easier to debug if you get into the habit of actually formatting the layout correctly as you write it.

For instance, look at the program below


	#include<stdio.h>
	main()
	   {
	    int sum,loop,kettle,job;
	    char Whoknows;

	         sum=9;
	   loop=7;
         whoKnows='A';
	printf("Whoknows=%c,kettle=%d\n",whoknows,kettle);
	}

It is our contention that the program is hard to read, and because of this, will be difficult to debug for errors by an inexperienced programmer. It also contains a few deliberate mistakes!

Okay then, lets rewrite the program using good form.


	#include <stdio.h>

	main()
	{
		int sum, loop, kettle = 0, job;
		char whoknows;

		sum = 9;
		loop = 7;
		whoknows = 'A';
		printf( "Whoknows = %c, kettle = %d\n", whoknows, kettle );
	}

We have also corrected the mistakes. The major differences are


©Copyright B Brown. 1984-1999. All rights reserved.