Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts
command line arguments in linux shell script
args.sh
echo "Total Number of Argument : "$#
echo "Programe Name : "$0
n=0
for i in $*
do
n=`expr $n + 1`
echo "\nArgumnet [ "$n" ] : "$i
done
echo "Programe Name : "$0
n=0
for i in $*
do
n=`expr $n + 1`
echo "\nArgumnet [ "$n" ] : "$i
done
Example of command line argument in C on Linux
args.c
#include "stdio.h"
void main(int c, char *argv[])
{
int i;
for(i=0;i<c;i++)
{
printf("\nargument[%d] : %s",i,argv[i]);
}
}
void main(int c, char *argv[])
{
int i;
for(i=0;i<c;i++)
{
printf("\nargument[%d] : %s",i,argv[i]);
}
}
Block Parity Check - Error Detection and Correction Techniques
Sender / Block Parity Generator
//block parity sender
#include<stdio.h>
#include<string.h>
#include<fcntl.h>
// one bit for NULL char and
// second for Parity bit
#define Frame_Size 32 // size of frame in bit
#define ROW 4+1 //segments
#define COL 8+2 // m bits in a segment [ +2 for '*' and '\0' ]
int getBit(int frameData,int pos)
{
//get binary equavalient of our Frame Data by setting on bit by bit
int code=1; // take base of binary 1 [ 00000001 ]
code=code<<(pos-1); // do the left shift to find postion
if(frameData & code) // if both bits are 1 then set bit otherwise return ZERO
return 1;
else
return 0;
}
void blockParity(char myframe[ROW][COL])
{
int i=0,j=0,ROW_count=0,COL_count=0;
//[ Horizontal parity ]
for(i=0;i<ROW;i++)//ROW's Parity Check
{
ROW_count=0;
for(j=0;j<COL-2;j++) //we r using -2 because we want to exclude last two bit that is * and NULL
{
if(myframe[i][j] == '1')//count ROW Parity
{
ROW_count++;
}
}
if((ROW_count % 2) == 0) //set ROW parity bit
myframe[i][j] = '0' ;
else
myframe[i][j] = '1';
}
//[ Virtical parity ]
for(i=0;i<COL-2;i++)//COL's Parity
{
COL_count=0;
for(j=0;j<ROW;j++)
{
if(myframe[j][i] == '1')//count COL Parity
{
COL_count++;
}
}
if((COL_count % 2) == 0) //set COL parity bit
myframe[ROW-1][i] = '0' ;
else
myframe[ROW-1][i] = '1';
}
}
Checksum - Error Detection and Correction Techniques
checksum.h
//checksum header file
#include<stdio.h>
#include<string.h>
# define segment_len 8
# define no_segments 4
# define frameSize 32
int getBit(int frameData,int pos)
{
int code=1; //base
code=code<<(pos-1);
if(frameData & code)
return 1;
else
return 0;
}
void sum(char segment1[],char segment2[])
{
int i,j;
//int segment_len=strlen(segment1);
int ans=0,carry=0;
char ans_segment[9]=" ";
// segment_len--;//because starting from zero
for(i=segment_len-1;i>=0;i--)
{
ans=0;
ans=( (int)segment1[i]-48 ) + ( (int)segment2[i]-48 ) + carry; //sum of bits on each position of two segments
if(ans>=2)//carry genrated
{
carry=1;
if(ans==2)
ans=0; // 1 + 1 = 10 ans
else
ans=1;// 1 + 1 + 1(carry) = 11 ans
}
else
{
carry=0;
}
ans_segment[i]=ans+48;
}
ans_segment[segment_len+1]='\0';
strcpy(segment1,ans_segment);
if(carry==0)
return;
else
sum(segment1,"00000001"); //recursive call of function if carry genrated
}
void complement(char segment[])
{
int i,len=strlen(segment);
for(i=0;i<len;i++)
{
if(segment[i]=='1')
segment[i]='0';
else
segment[i]='1';
}
segment[i]='\0';
}
Byte Stuffing - Framing Technics
Sender
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
#define FLAG '#'
#define ESC '*'
void main()
{
int j=1,i,pid;
char Frame_Data[50],Targeted_Frame[50];
system("clear");
system(">pipe");
pid=open("pipe",O_WRONLY);
printf("Enter the Frame Data : ");
scanf("%s",Frame_Data);
Targeted_Frame[0]=FLAG; //set header FLAG
for(i=0;i<strlen(Frame_Data);i++)
{
if (Frame_Data[i]==FLAG || Frame_Data[i]==ESC) //check FLAG or ESCAPE charechter is in frame data
{
Targeted_Frame[j++]=ESC; // if FLAG / ESCAPE Char found add one more ESCAPE char
}
Targeted_Frame[j++]=Frame_Data[i]; //copy other data
}
Targeted_Frame[j++]=FLAG; //set tailer FLAG
Targeted_Frame[j]='\0';
printf("\nFrame to be send : %s",Targeted_Frame);
write(pid,&Targeted_Frame,sizeof(Targeted_Frame));
close(pid);
}
Single Bit Parity Check
Sender
/*Single bit Parity check*/
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
int getBit(int frameData,int pos)
{
//get binary equavalient of our Frame Data by setting on bit by bit
int code=1; // take base of binary 1 [ 00000001 ]
code=code<<(pos-1); // do the left shift to find postion
if(frameData & code) // if both bits are 1 then set bit otherwise return ZERO
return 1;
else
return 0;
}
int getParity(char targeted_frameData[])
{
//find the even parity
int i=0,counter=0;
for(i=0;i<32;i++)
{
if(targeted_frameData[i]=='1') //count total no. of 1
counter++;
}
if(counter % 2 == 0 )//Even parity
return 0;
else
return 1;
}
void main()
{
int frameData,i,k=0,flag,pid,frame_size=32;;
char targeted_frameData[34];
pid=open("pipe",O_WRONLY);
//Enter Frame Data in decimal Number
printf("\nEnter Frame Data : ");
scanf("%d",&frameData);
for(i=frame_size;i>0;i--)
{
targeted_frameData[k++]=getBit(frameData,i) + 48;
}
//Set Parity bit
targeted_frameData[k++]=getParity(targeted_frameData) + 48;
targeted_frameData[k++]='\0';
printf("\n\nTageted Frame : %s\n",targeted_frameData);
write(pid,&targeted_frameData,sizeof(targeted_frameData));
close(pid);
}
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
int getBit(int frameData,int pos)
{
//get binary equavalient of our Frame Data by setting on bit by bit
int code=1; // take base of binary 1 [ 00000001 ]
code=code<<(pos-1); // do the left shift to find postion
if(frameData & code) // if both bits are 1 then set bit otherwise return ZERO
return 1;
else
return 0;
}
int getParity(char targeted_frameData[])
{
//find the even parity
int i=0,counter=0;
for(i=0;i<32;i++)
{
if(targeted_frameData[i]=='1') //count total no. of 1
counter++;
}
if(counter % 2 == 0 )//Even parity
return 0;
else
return 1;
}
void main()
{
int frameData,i,k=0,flag,pid,frame_size=32;;
char targeted_frameData[34];
pid=open("pipe",O_WRONLY);
//Enter Frame Data in decimal Number
printf("\nEnter Frame Data : ");
scanf("%d",&frameData);
for(i=frame_size;i>0;i--)
{
targeted_frameData[k++]=getBit(frameData,i) + 48;
}
//Set Parity bit
targeted_frameData[k++]=getParity(targeted_frameData) + 48;
targeted_frameData[k++]='\0';
printf("\n\nTageted Frame : %s\n",targeted_frameData);
write(pid,&targeted_frameData,sizeof(targeted_frameData));
close(pid);
}
Character Count - Framing Technics
Sender
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
void main()
{
int Frame_Count,j=0,len,i,k,pid;
char Frame_Data[50],targeted_frame[100];
system("clear");
system(">pipe");
pid=open("pipe",O_WRONLY);
printf("How many Frame you data want to send : ");
scanf("%d",&Frame_Count);
for(i=0;i<Frame_Count;i++)
{
printf("\nEnter Frame [%d] : ",i);
scanf("%s",Frame_Data);
len=strlen(Frame_Data);
targeted_frame[j]=len+1+48; //set Header [header + total char followed by header]
for(k=0;k<len;k++)
{
j++;
targeted_frame[j]=Frame_Data[k];
}
j++;
}
targeted_frame[j]='\0';
printf("\nFRAME TO SEND : %s",targeted_frame);
write(pid,&targeted_frame,sizeof(targeted_frame));
}
/*2i5love6india*/
Bit Stuffing - Framing Technics
Sender
#include<stdio.h>
#include<string.h>
#include<fcntl.h>
int getBit(int frameData,int pos)
{
//get binary equavalient of our Frame Data by setting on bit by bit
int code=1; // take base of binary 1 [ 00000001 ]
code=code<<(pos-1); // do the left shift to find postion
if(frameData & code) // if both bits are 1 then set bit otherwise return ZERO
return 1;
else
return 0;
}
void bitStuffing(char myFrame[])
{
// stuffing procedure
int i=0,k=0,counter=0;
char temp[50];
strcpy(temp,myFrame);
while(temp[i]!='\0')
{
myFrame[k++]=temp[i]; // update Frame data by doing Stufing
if(temp[i]=='1')
{
// if we encounter continues 1 then do increment in counter
counter++;
}
else
{
// if continuty of 1's break, reset counter to ZERO
counter=0;
}
if(counter==5)
{
// after a FIVE consicutive ONE stuff a bit ZERO
myFrame[k++]='0';
}
i++;
}
myFrame[k]='\0';
}
void main()
{
int pid,i,no,k=0,frameData,frame_size=32;
char myFrame[50];
system(">pipe");
pid=open("pipe",O_WRONLY); // open named pipe for write mode
system("clear");
//Enter Frame Data in decimal Number
printf("\nEnter Frame Data : ");
scanf("%d",&frameData);
for(i=frame_size;i>0;i--)
{
myFrame[k++]=getBit(frameData,i)+48;
}
myFrame[k]='\0';
printf("\nBefore Stuffing Frame : %s",myFrame);
bitStuffing(myFrame); // do the process of bit Stuffing
printf("\nAfter Stuffing Frame : %s\n\n",myFrame);
write(pid,&myFrame[0],sizeof(myFrame)); //write frame in to named pipe
}
Subscribe to:
Posts (Atom)
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- CSS (3)
- Configure Tomcat7 (2)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- WTAD (34)
- c (11)
- install Tomcat (2)
- linux (8)
- shell script (33)
- unix (22)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.