//c++ program to reverse string
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<fcntl.h>
#include<errno.h>
#include<string.h>
void client(int);
void server(int);
int main()
{
int pipe1[2];
pid_t childpid;
pipe(pipe1);
childpid=fork();
if(childpid==0)
{
wait();
close(pipe1[1]);
server(pipe1[0]);
}
else
{
close(pipe1[0]);
client(pipe1[1]);
}
}
void client(int writefd)
{
int len,n;
char buff[80];
printf("enter the string:\n");
fgets(buff,80,stdin);
len = strlen(buff);
if(buff[len-1]=='\n')
{
len--;
}
write(writefd,buff,len);
}
void server(int readfd)
{
int fd,n,i,j;
char str[80],temp;
n=read(readfd,str,80);
str[n]='\0';
i=0;
j=strlen(str)-1;
while(i<j)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
i++;
j--;
}
printf("\nthe reverse of string:%s",str);
}
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<fcntl.h>
#include<errno.h>
#include<string.h>
void client(int);
void server(int);
int main()
{
int pipe1[2];
pid_t childpid;
pipe(pipe1);
childpid=fork();
if(childpid==0)
{
wait();
close(pipe1[1]);
server(pipe1[0]);
}
else
{
close(pipe1[0]);
client(pipe1[1]);
}
}
void client(int writefd)
{
int len,n;
char buff[80];
printf("enter the string:\n");
fgets(buff,80,stdin);
len = strlen(buff);
if(buff[len-1]=='\n')
{
len--;
}
write(writefd,buff,len);
}
void server(int readfd)
{
int fd,n,i,j;
char str[80],temp;
n=read(readfd,str,80);
str[n]='\0';
i=0;
j=strlen(str)-1;
while(i<j)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
i++;
j--;
}
printf("\nthe reverse of string:%s",str);
}
No comments:
Post a Comment