c language

Only available on StudyMode
  • Download(s) : 12
  • Published : November 15, 2013
Open Document
Text Preview
Learn C Programming, A short C Tutorial
So you want to be a hero.... I mean programmer, well by reading this tutorial maybe we'll be able to help you accomplish your goal. First a little about C and its derivative C++. It is considered to be the most commonly used programming language. If you want a job in programmming, you will need to know this language. But what makes C the language that everyone wants to use. Well, its been around for quite some time. The original C since the 70s, and C++ since the early 80s, which is like eons in computer time. C is the most versatile high level language. C permits just about anything, allowing programmers to write straight to the metal. Its code runs very fast. Note that this tutorial will not cover C++ (C with classes). Table of Contents:

Your First Program
Data Types and Printf
Loops and Conditions
Pointers and Arrays
Functions
Other Resources
This tutorial is meant to be a brief introduction to C, it is by no means exhaustive. If you need more information try looking at our Other Resources. Learning a programming language is a lot like learning a language that people speak like German or French. The best way to learn a 'human' language is to start speaking, listening, and repeating, and then leaving the grammar for later. The same can be applied to C, you need to start writing programs as quickly as possible. So, this tutorial will provided a lot of well commented sample programs that you can run and tinker with. 1. Your First Program

If you've ever read another tutorial or a book on a programming language, then you've probably seen a program like this before. The hello world program. It is a perfect starting place for our tutorial. So, type the following program into your favorite editor. If you are using Windows then try notepad or DOS Edit, if using a *Nix variant use VI or emacs. Without further adew here is the program : /* hello world program */

#include "stdio.h"

void main()
{
printf("\nHello World\n"); // print to screen
}
Save this code into a file, and call the file hello.c, then compile it by typing at a command prompt: gcc hello.c
If you are using *Nix you should have an a.out file now, but if you are using Windows you might be wondering what is gcc, and where do I type the above line into. On Windows getting up and started with C is little bit more difficult than with a *Nix variant. You can get a variation of gcc to output Windows code called DJGPP at www.delorie.com/djgpp/ Setting up the compiler is probably the hardest part to getting started programming, and unfortunately this site doesn't cover setting up DJGPP. Another compiler option is to get Microsoft Visual C++, an excellent editor, with lots of nice features. The draw back is that the standard edition costs around $100. But if you can afford a copy, get it. If you have Visual C++ and it is already installed then load it, click File, then New, then select Win32 Console application from the project list. Type in a project name, and then press ok. Next it will ask you what it should automatically create. Select the hello world application, and then you should get a program very similar to the one above. F7 compiles, and Ctrl-F5 will run it. From now on the tutorial will refer to the *Nix method and output files. If you compiled the program in Windows instead of *Nix you would have a hello.exe instead of a a.out Note:If you are coming from the gameboy advance tutorial, please note you will need a separate compiler for this tutorial. The reason is the gcc with the devkit advance is for the gameboy, so the code it generates will not run on a PC, also becuase the gameboy has no standard font built in, you will not be able to see the output of the printf statement, basically the above program will do nothing. This creates an executable file a.out, which is then executed simply by typing its name. The result is that the characters Hello World are printed out, preceded by an empty...
tracking img