C langugae : C Programming in Linux

Why learn the C language in Linux
Because the C language is like Latin - it is finite and has not changed for years. C is tight and spare, and in the current economic climate we will need a host of young people who know C to keep existing critical systems running.
C is built right into the core of Linux and Unix. The design idea behind Unix was to write an operating system in C so all you needed to port it to a new architecture was a C compiler. Linux is essentially the success story of a series of earlier attempts to make a PC version of Unix.
A knowledge of C is now and has been for years a pre-requistie for software proffesionals and with the recent propularity and maturity of Open Systems this is evern more true. The terseness and preceived difficulty of C Saw it being ousted from university teaching the late 1990s in favour of Java but there is a growing feeling amongst some teaching communities that Java really is not such a good place to start beginners.
Setting up your System
These notes presumes you are using the Linux operating system with either the KDE3.5, KDE4 or Gnome desktop. Specific instructions are included for Ubuntu (and Kubuntu) and OpenSuse 11.
If you are using the KDE desktop you will have Konqueror or Dolphin as the File Manager and kate or kedit for an editor.
In Gnome you would probably use Nautilus and gedit.
You need to be familar with the idea of doing some things as "super user" so that you have access permission to copy or edit certain files. This is normally done by prefacing the Linux command with "sudo" and providing the password, as in this example:
"sudo cp hello / srv/www/cgi-bin/hello3"
which copies the file "hello3" to the area where the Apache server locates common gateway inferace or cgi programs
In KDE "Kdesu konqueror" would open a file manager as super user.
In Gnome "gnomesu nautilus" would open a file manager as super user.
You will need to have installed the following packages:

Throughout the text you will see reference to the folder cgi-bin. The location of this will vary between Linux distributions. By default this folder used for web program is: OpenSuse: /srv/www/cgi-bin Ubuntu: /usr/lib/cgi-bin How to Execute the program in Linux
Using the File Manager create a new directory somewhere in your home directory called something appropriate for all the examples in this lecture notes " C prgram in Linux" without any space in the name.
Open an editor (in KDE, kate, or in Gnome, gedit) and type in (or copy from the supplied source code zip bundle) the following:
/******************************************/
C Progamming in linux
/******************************************/
# include < stdio.h >
int main (int argc, char *argv[])
{
printf("Hello, you are learning C!!\n" );
return 0;
}
Save the text as anuj1.c in the new folder you created in your home directory.
open a terminal window and type: gcc-o hell anuj1.c
to compile the program into a form that can be executed.
Now type "ls-l" to list the details of all the files in this directory. You should see the anuj1.c there and a file called "hello" which is the compiled c program you have just written.
Now type : - ./hello
to execute, or run the program and it should return the text;
"Hello you are learning C!!".


Free Web Hosting