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