Naman Khybri
Naman Khybri
SERVER-SIDE CODE :-
#include <stdio.h>
#include <netdb.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h> // read(), write(), close()
//fuction for reading from user
int r_read(int res){
char buf[100],ans[100];
int ctr=0;
res=open("myfifo",O_RDONLY);
read(res,buf,100);//reading data from pipe
for(int i=1;i<sizeof(buf);i++)
{
if(buf[i]=='$')
{
ans[ctr]=buf[i+1];
i++;
} //Decoding data from pipe
else{
ans[ctr]=buf[i];
}
if(buf[i]=='#'&&buf[i+1]=='\0')
{
ans[ctr]=buf[i+1];//for erasing end #
}
ctr++;
}
ASSIGNMENT - IV 1
CLIENT-SIDE CODE :-
#include <stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include <string.h>
#include <unistd.h>// read(), write(), close()
#include <stdlib.h>
//staring of main
int main()
{
int res,code;//response pointer
char buf[100];
char newmsg[100];//newmsg buffer
int ctr=1;//counter Setting
char newbuf[2]="#";
printf("enter any word: ");
scanf("%s",buf);//Taking Input for user
newmsg[0]='#';
for(int i=0;i<sizeof(buf);i++){
if(buf[i]=='#'||buf[i]=='$'){
newmsg[ctr]='$';
newmsg[ctr+1]=buf[i];
ctr++;
ctr++;
}
else{
newmsg[ctr]=buf[i];
ctr++;
}
}
strcat(newmsg,newbuf);
printf("data is: %s\n",newmsg);
res=open("myfifo",O_WRONLY);
write(res,newmsg,100);
printf("\nconnection ends...\n");//connection terminated
return 0;
OUTPUT :-
ASSIGNMENT - IV 2
SERVER :
CLIENT :
ASSIGNMENT - IV 3