Sunday, September 16, 2012

CONDITIONAL AND SWITCH


            In GCC, conditional and switch programming is as like Windows (TC).

CONDITIONAL PROGRAMMING
            Conditional program has structure in Windows (TC) as

if(condition1)
{
            statements;
}
else if(conditon2)
{
            statements;
}
else
{
            statements;
}

This is same structure for GCC.

SWITCH-CASE PROGRAMMING
            switch-case programming has structure in Windows (TC) as

switch(choice)
{
            case 1: statements;
                        break;
            case 2: statements;
                        break;
            case 3: statements;
                        break;
            .
            .
            .
}

This is also same structure for GCC.

Let’s check some examples of these…
  1)    CONDITONAL PROGRAM

#include<stdio.h>
#include<string.h>
int main()
{
      float age=0.0;
      char concetion[10]="NULL";

      printf("\n\n Concetion Rate Board");
      printf("\n\n Enter your age : ");
      scanf("%f",&age);
      if(age<=18)
                  strcpy(concetion,"FULL");
      else if(age>=60)
                  strcpy(concetion,"HALF");
      else
                  strcpy(concetion,"NO");
      printf("\n You have %s concetion",concetion);
      printf("\n");
return 0;
}

  2)    switch-case program

#include<stdio.h>
#include<stdlib.h>
int main()
{
            int choise=0;
            float amount=0.0;
            printf("\n Transaction Unit");
            printf("\n 1-Deposite        \
                        \n 2-widrowal \
                        \n 3-exit        \
                        \n Enter your choice (1/2) : ");
            scanf("%d",&choise);
            switch(choise)
            {
            case 1: printf("\n\n Enter amount you want to Deposite : ");
                        scanf("%f",&amount);
                        printf(" Your %.2f amount is Deposited !!!",amount);
                        break;

            case 2: printf("\n\n Enter amount you want to Widraw : ");
                        scanf("%f",&amount);
                        printf(" Your %.2f amount is Widrawed !!!",amount);
                        break;

            case 3: printf("\n\n You have entered option to exit.");
                        exit(0);

            default: printf("\n\n You have entered incorrect option !!!");

            }
            printf("\n");
return 0;
}

Saturday, September 8, 2012

Header Files

"Header file" is a file which contains prototypes or declarations of certain required functions or macros or variables. Functions -those declared in header files- has a benefit that those can be reused,recalled. Because of "Header file concept", programming became easy; otherwise in past, programmer need to write whole code for each function or macro or variables or concepts, each time !!!!!

For example, in C compiler-GCC, prototype of printf(), scanf() functions is declared(written) in stdio.h file. But in FORTRAN language, because of absence of "header files", programmer wrote complete coding of scanning, printing, exiting and all processes -each time.

The C Pre-Processor links those functions to their header files and replaces those functions with their complete prototype. Header files need to included at the starting of C code.
All header files are located in "/usr/include" directory

GCC contain all ANSI  approved header files only. But most of other compilers, create and put their own header files. You can include or install other .h files in GCC. All header files in GCC and Borland TC are given below. Hope they will help you !!!


STANDARD
OR GCC
BORLAND


assert.h
alloc.h
complex.h
bios.h
ctype.h
conio.h
errno.h
dir.h
fenv.h
dirent.h
float.h
dos.h
inttypes.h
fnkeys.h
iso646.h
graphics.h
limits.h
generic.h
locale.h
io.h
math.h
process.h
setjmp.h
share.h
signal.h
sys\stat.h
stdarg.h
TurboC.h
stdbool.h

stddef.h

stdint.h

stdio.h

stdlib.h

string.h

tgmath.h

time.h

wchar.h

wctype.h




Friday, September 7, 2012

Some Linux Commands !!!



COMMAND
DESCRIPTION
SYNTAX



who
show who is logged on
who
su
change user ID
su <loginname>
passwd
to change your password
passwd
man
displays details of a command
man <command_name>
ls
list directory contents
ls
mkdir
make directories
mkdir <foldrname>
cd
changes directories
cd
cp
copy files and directories
cp a.txt copy.txt
mv
move files
cp a.txt <directory>
rm
remove files or directories
rm file1.txt
find
search for files in a directory
find file1.txt
pwd
print name of current working directory
pwd
history
prints recently used commands
history
mount
mount a file system or drive
mount /media/target
umount
unmount file systems or drive
unmount /media/target
poweroff
shut down the system
poweroff
reboot
restart the system
reboot
vim
A programmer’s text editor
vi hello.c
gedit
A text Editor
gedit hello.c
cal <month> <year>
display calendar
cal april 2012
date
displays the current date
date
echo
Print message on the terminal
echo "Welcome to the workshop"
printf
Print the formatted message on the terminal
printf "the amount is %d\n" 100
bc
A text based calculator
bc
xcalc
A graphical based calculator
xcalc
gcc
To compile C program file
gcc file1.c
g++
To compile C++ program file
g++ file1.c
ctrl+d
Quit command process