Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ Programming
➜ General
➜ New Coders...Read
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Nick Cash
USA (626 posts) Bio
|
Date
| Fri 06 Feb 2004 02:05 AM (UTC) Amended on Fri 06 Feb 2004 02:08 AM (UTC) by Nick Cash
|
Message
| 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. |
~Nick Cash
http://www.nick-cash.com | Top |
|
Posted by
| Greven
Canada (835 posts) Bio
|
Date
| Reply #1 on Fri 06 Feb 2004 03:32 AM (UTC) |
Message
| 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. |
Nobody ever expects the spanish inquisition!
darkwarriors.net:4848
http://darkwarriors.net | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
8,362 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top