Click here to Skip to main content
15,881,027 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to Write a C program that forks a child. The parent and child use two anonymous pipes to communicate. The parent sends a message to the child. The message is received by the user through a command line argument. The child needs to find how many space ' ' characters are there in the input message. The child returns this count to the parent through a pipe, and the parent displays this count by printing a message to the standard output. Show your program and a sample run session.

• The parent and child should close the unused ends of their pipes
• Assume that the maximum input size is 100 characters

Can anyone help?

What I have tried:

This is what I have tried

#include <sys types.h="">
#include <sys ipc.h="">
#include <stdlib.h>
#include <stdio.h>
#include <sys wait.h="">
#include <unistd.h>
#include <string.h>
#define SIZE 1024

int main( int argc, char const *argv[]){
{
int Childfd[2];
int Parentfd[2];
pid_t child;
int no;
char buf[SIZE];
char result[SIZE];
char inputMessage[SIZE];
int i=0, space=0 no;
pipe(childfd);
pipe(parentfd);

int pid = fork();

if (pid == 0)
{
//child
close(Childfd[1]);
close(Parentfd[0]);

no=read(Parentfd[0], buf, sizeof(buf));

while (read(buf(Childfd[i]!='\0')
{
for (int i=0; i
Posted
Updated 12-Oct-22 20:18pm
Comments
Rick York 13-Oct-22 1:53am    
Help do what? Your code is incomplete.

1 solution

I wonder if we could find some help on the web... C Program to Demonstrate fork() and pipe() - GeeksforGeeks[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900