CS19001/CS19002 Programming and Data Structures Laboratory

Autumn/Spring semester

Getting started


The basic cycle


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).


On-line help


Your first C program

The following program prints Hello world! and terminates. They said it in the Bible that whenever you start learning programming, you must first write this program. And nothing else.
   #include <stdio.h>

   main ()
   {
      printf("Hello world!\n");
   }
Complete your edit-save-compile-debug-run cycle on this code. Though it is not written in the Bible, we guarantee that none of your future programs will be as easy as this. So quickly get habituated to this programming process of Unix. (Somebody of you may have experience with an integrated development environment (IDE) 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.)


The second C program

Now it's a more complicated piece of code. For the time being, blindly (but with your eyes open) type this code and run. Just get acquainted to the process. And, of course, save this second program in a new file.
   #include <stdio.h>

   char name[100];
   int i;

   main ()
   {
      printf("Hello, may I know your full name ? ");
      scanf("%s",name);
      printf("Welcome %s.\n",name);
      printf("Your name printed backward is : ");
      for (i=strlen(name)-1; i>=0; i--) printf("%c",name[i]);
      printf("\n");
   }
Have you noticed something bad during the execution? You may now try the following:
   #include <stdio.h>

   char name[100];
   int i;

   main ()
   {
      printf("Hello, may I know your full name ? ");
      fgets(name,100,stdin);
      name[strlen(name)-1] = '\0';
      printf("Welcome %s.\n",name);
      printf("Your name printed backward is : ");
      for (i=strlen(name)-1; i>=0; i--) printf("%c",name[i]);
      printf("\n");
   }
OOPS! It's not so easy then. Don't worry. The entire semester is waiting.


Course home