Wednesday, March 23, 2016

a value in an array is passing to a function Example

                   value in an array is passing to a function Example
Same as the previous program but the simple difference which is Red colourly quoted pointer calling 

#include
#include

int array_test(int arra[]);
int main ()
{

     int line[5] = {10,20,30,40,50};
array_test(line );
return 0;
getch();
}

array_test(int arra1[])
{
int i;
printf("arra value is  ");
for(i=4; i>-1; i-- )
          printf(" _%d ",*arra1++);
return 0;
}

a value in an array is passing to a function Example

                         A  value in an array is passing to a function Example 

#include
#include

int array_test(int arra[]);  // function
int main ()
{

     int line[5] = {10,20,30,40,50};        // array value named line
array_test(line );                           // array value passed to the function by function call
return 0;
getch();

}

array_test(int arra1[])        // function and declared an array named as arra1 to take the value from line
{
int i;
printf("arra value is  ");
for(i=4; i>-1; i-- )
          printf(" _%d ",arra1[i]);
return 0;
}


Tuesday, March 15, 2016

getbit() function K&R 2.9

                                    getbit() function 










#include
#include
int getbit(unsigned number, int position,int width )
{
return(number>>(position+1-width)) & ~(~0<

}

 int main ()

   {       unsigned int a ;
   
    a = getbit(0xA7,6,4);
    printf(" The extracted bit is %d = ", a);
    return 0;
    getch();
   

   }

Sunday, March 13, 2016

atoi(char s[]) function

                                    atoi(char s[]) function 


#include
#include

int atoi( char s[])
{
int n,i;
 n = 0;
 

for(i = 0; s[i] >= '0' && s[i] <= '9'; ++i)
 n=  10 * n + (s[i] - '0');
 return n;
}

int main()
{
int c;
char s[]= {'3','4','9'};
c= atoi(s);

printf("%d",c);
 
getch(); 
return 0;

}

Friday, March 11, 2016

Use of enum data type

                   Use of enum data type  example  

#include
#include
            enum portselector { port1 = 1, port2,port3,port4
                                              } selected;
void port(enum portselector);

int main(void)
{
   int data;
   printf("Enter the port you want  -Port1=1,...,Port4 =4\n");
   scanf("%d", &data);
    
   selected=data;
   port(selected);
   printf("\n\nGiven Number is  = %d  ",data);
   
   getch();
   return(0);
}
void port(enum portselector selected)
{
   switch (selected)
   {
      case port1:
         printf("port1 selected\n");
         break;
      case port2:
         printf("port2 selected\n");
         break;
      case port3:
         printf("port3 selected.\n");
         break;
 case port4:
         printf("port4 selected\n");
         break;
      
      default:
         printf("no port available hi hi hi  only 4 ports .\n");
   }
}



 whenever the function pass the value (int data = selected)  the switch case check the number .

Monday, March 7, 2016

File Coping

Read character and print until the end of file EOF 

Here the program to copy or read by getchar() function And  the words or character  print it by putchar() function 

#include
#include

int main()
{
char a;

while((a=getchar()) != EOF)
putchar(a);
getch();
return 0;


}

See the out put 



Use of getchar() ,putchar() functions

     
                             Use of getchar() ,putchar() functions

The use of getchar function is to capture or get the data / the typed character from (single chara) keyboard .

the putchar() is do just opposite of getchar()

It prints directly to the screen , so we dont need use the printf() function .

Look the program and output

here used getchar() function  to get char.
putchar() and printf() function is used to print the given data.