[ SENDER SIDE ]
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
void main()
{
int no,j=0,len,i,k,pid;
char data[50],frame[100];
system("clear");
system(">pipe");
pid=open("pipe",O_WRONLY);
printf("Enter how many data want to enter: ");
scanf("%d",&no);
for(i=0;i<no;i++)
{
printf("\nEnter data : ");
scanf("%s",data);
len=strlen(data);
frame[j]=len+1+48;
for(k=0;k<len;k++)
{
j++;
frame[j]=data[k];
}
j++;
}
frame[j]='\0';
printf("\nFRAME TO SEND : %s",frame);
write(pid,&frame,sizeof(frame));
}
[ RECEIVER SIDE ]
#include<stdio.h>
#include<fcntl.h>
#include<string.h>
void main()
{
int no,j=0,len,i=0,k,pid;
char data[50],frame[100];
system("clear");
pid=open("pipe",O_RDONLY);
read(pid,&frame,sizeof(frame));
while(frame[i]!='\0')
{
len=frame[i]-48;
i++;
for(k=0;k<len-1;k++)
{
data[k]=frame[i];
i++;
}
data[k]='\0';
printf("\ndata %s",data);
}
}
HI
ReplyDeletehow to run
ReplyDeleteThanks!
ReplyDeleteMazze aa gaye :)