CS13002 Programming and Data Structures | Spring semester |
Getting started
The basic cycle
- Switch on your monitor.
- Switch on your PC.
- Allow the machine to boot. Wait till the login prompt comes.
- Supply your login and password:
Login: d<nn> Password: d<nn>Here <nn> is the number of your PC. This opens your window manager (usually KDE) with icons, the bottom panel and so on. You are now ready to start your work.- Click on the terminal icon to open a shell (command prompt).
- Edit your program (new or already existing) by an editor. We recommend using the emacs editor. This is how you can run emacs:
emacs myprog.c &(Note that the ampersand in the last command was not necessary, but is helpful in the sense that it runs emacs in the background and the shell is free to listen to your other commands.)- Write your program in the editor and save it.
- Go to the shell and compile your program:
cc myprog.cIf compilation is successful, an executable called a.out will be created.- Run your program:
a.outYou may have to give the command ./a.out in case you are issued a message like a.out: Command not found.- Continue your edit-compile-debug-run-debug-print work.
...
Finally, it's pretty late. It's time to pack up. Wait! You still have some more things to do, before you rush for your lunch.
- Close all the windows you opened.
- Logout from your window manager. This leaves you again in the login console.
- Select the item to shut down the machine. Wait till the machine completely shuts down.
- Switch off your monitor.
- You can now leave. Don't remember later that you have forgot to sign the attendance sheet. You may not rely on our memory to certify in the next week that you were present in this lab session.
Some useful Unix commands
Here is a short list of useful commands that you can use from your shell (in addition to running emacs and compiling and running your program).
- Create a directory:
mkdir progs- Go to a new directory:
cd progs/Every directory provides you access to two directories: . (the current directory) and .. (the parent directopry).- View a list of all files in a directory:
ls -lFNote that ls -F, ls -l, ls -al, ls -alF etc and even simply ls also work. Try out and find the differences. In fact, the ls takes a lot of other options.- View the content of a file:
cat filename- Copy one file to another:
cp file1.c file2.c cp file2.c mydir/file3.c- Move a file to another:
mv file1.c file2.c mv file2.c mydir/ cd mydir/ mv file2.c ../file1.c cd ../- Delete a file:
rm filenameNote: A deleted (by rm) or overwritten (by mv) file is lost for ever. In no way you can get it back. Be very, very careful, before running these commands.
On-line help
- Click on your browser icon and run either mozilla (also known as netscape) or konqueror.
- Visit the following URL:
http://facweb.iitkgp.ernet.in/~adas/course/lab/PDS/Spring05/
You may bookmark this link in your browser.
Your first C program
#include <stdio.h> main () { printf("****\n"); /* whatever is between quotes is printed verbatim */ printf("* *\n"); /* \n advances the cursor to the next line */ printf("* *\n"); printf("****\n"); printf("* *\n"); printf("* *\n"); printf("****\n"); }Complete your edit-save-compile-debug-run cycle on this code. (Somebody of you may have experience with an integrated environment like TURBO C or Microsoft VC++. In Unix such an environment is generally missing. But that's not a big issue, as you will understand soon.)Modify the above program to print a banner for "35".
The second C program
#include <stdio.h> #define pi 3.14159 /* This program finds solutio to the simultaneous equations*/ /*a1.x + b1.y = c1 and a2.x + b2.y = c2 */ main () { float x,y, a1,b1,c1,a2,b2,c2; printf ("\nEnter a1 b1 c1 a2 b2 c2: "); scanf ("%f%f%f%f%f%f", &a1, &b1,&c1,&a2,&b2,&c2); printf ("%f %f %f %f %f %f", a1, b1, c1, a2, b2, c2); x= (c1*b2-c2*b1)/(a1*b2-b1*a2); y= (a1*c2-a2*c1)/(a1*b2-b1*a2); printf ("\nValues of x and y are %f and %f\n",x,y); }Does it work for ALL situations ?
[Course home] [Lab home]