New Coders...Read

Posted by Nick Cash on Fri 06 Feb 2004 02:05 AM — 2 posts, 9,725 views.

USA #0
Any new coders out there? I've got some suggestions for you:

First off, get a book. The one I have is Teach Yourself C (third edition) by Herbert Schildt. Other people, such as Greven, Nick, or Ksilyan will no doubt recommend others.

Second, get a good compiler. If you run windows then lcc-win32 is a very good free Windows compiler. Of course *nix comes with gcc, which is what I've used for almost all of my coding.

Third, READ. Lots of reading involved. Read and you will learn.

Fourth, try. Try a simple program, like the one later in this post. Write your own, try some stuff thats really simple. One of the best ways to learn is to mess stuff up.

Lastly, when in doubt, post here. There are always helpful people.

Lets take a look at the first program everyone should write..

While looking through my C book it said the programs were all able to compile. Now, back when I was more noobish I found that no, it wouldn't work. However, I never thought to make it a console program.

In lcc-win32 make a new project, go ahead and configure the stuff (hopefully you'll figure it out), but make sure you click "console application". When done, try the programs below.

Note 1: You should be able to understand what printf does and the include statement at the top if you've read through the first chapter or two of your book.

Note 2: To run these after you have compiled (in windows) open Start, go to run and type in command. A Command Prompt will show up. Drag the executable into the window and hit enter and the program will run. On *nix just hit ./executable_name. Of course executable_name will be whatever you make it to be.

#include <stdio.h>

int main ( void )
{
	printf( "Hello World!" );
	return 0;
}


Next is a simple calculator (note: this could be simpler):

#include <stdio.h>

int main (void)
{
	int x, y;
	char ch;

	printf( "Which do you wish to do?\n" );
	printf( "Add, Subtract, Multiply, or Divide?\n" );
	// force user to enter a vaild response
	do
	{
		printf("Enter first letter: ");
		ch = getchar();
	}
	while ( ch != 'A' && ch != 'S' && ch != 'M' && ch != 'D' );
	printf("\n\r");

	printf( "\n\rEnter value X: \n" );
	scanf("%d", &x);

	printf("\n\rEnter value Y: \n" );
	scanf("%d", &y );

	switch ( ch )
	{
		case 'A': printf("X+Y: %d", x+y);
				break;

		case 'S': printf("X-Y: %d", x-y);
				break;

		case 'M': printf("X*Y: %d", x*y );
				break;

		case 'D': if ( y != 0 ) printf("X/Y: %d", x/y );
	}

	return 0;
}


Now, whats the point of writing this? Hopefully someone will find it useful and maybe an easy reference on where to get started. Also, maybe some of the more experience people here could write a "How to compile" post or something. I dunno, I got about half-way done with this post and then almost deleted it. ::shrug:: You never know who you are gunna help.
Amended on Fri 06 Feb 2004 02:08 AM by Nick Cash
Canada #1
The first C books that I read where "Teach yourself C for linux programming in 21 days", on of the Sams books, as well as "Practical C programming", but I can't find it to tell you the auther, though it was nicknamed "The cow", one of the animal series books.

I personally had been coding for my mud for months before I ever looked at either of those books, and they cleared up ALOT of things for me( for example, what the '\0' meant). I knew HOW they worked, but not why, and that knowledge of WHY makes a big difference, to me anyways.