Need Help ?

Home >> Assignments >> computer_science >> Use C to write a program that: The source process reads information from a file (Therefore, you need to prepare a small text file for testing purpose).

(Solved): Use C to write a program that: The source process reads information from a file (Therefore, you need to prepare a small text file for testing purpose). ...



Use C to write a program that:

The source process reads information from a file (Therefore, you need to prepare a small text file for testing purpose).

The source process calls fork() to create the filter process.

The filter process reads information from the source process (passed via an anonymous pipe), converts the uppercase characters to lowercase ones and vice versa, and then prints out the converted characters to the screen.

How to create an anonymous pipe: pipe() API.

**** I attempted the problem, and it is shown in the picture, but it outputs: Segmentation fault (core dumped). I dont know whats wrong****

#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <fcntl.h> #include <ctype.h> #include <sys/wait.h> #include <sys/types.h> int main (void) char str[1000]; //buffer int ap[2]; //file descriptor FILE *fp; fpopen(text.txt, r)I/open file int x read (fp, str, 1000); fclose(fp); //close file pid t pipe; I/fork if ((pipe-fork))) /Ichild close (ap[1]) //close writing on first pipe char str[1000]: read (ap[0], str, 1000); I/read string on first pipe intx strlen (str); //convert upper to lower and vice versa for (int í = 0; i < strlen(str): i++) { if(isupper (str[i])) [ stri]tolower (str[i]) else stri]toupper (str[i]) rintf( nCases switched from uppercase to lowercase and vice versa:n printf(%s\n, str); close(ap[O]); else //parent close(ap[O]); int length-strlen (str) I/length of string write (ap[1], str, length+1); close (ap[1]): wait(NULL)//wait for child to send string

Show transcribed image text #include #include #include #include #include #include #include #include int main (void) char str[1000]; //buffer int ap[2]; //file descriptor FILE *fp; fpopen("text.txt", "r)I/open file int x read (fp, str, 1000); fclose(fp); //close file pid t pipe; I/fork if ((pipe-fork))) /Ichild close (ap[1]) //close writing on first pipe char str[1000]: read (ap[0], str, 1000); I/read string on first pipe intx strlen (str); //convert upper to lower and vice versa for (int í = 0; i



We have an Answer from Expert

View Expert Answer

Get Expert Solution


Code:

// define a header files

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

We have an Answer from Expert

Buy This Answer $5

Place Order

QUICK ORDER

Why Place An Order With Us?

  • Certified Editors
  • 24/7 Customer Support
  • Profesional Research
  • Easy to Use System Interface
  • Student Friendly Pricing
Order Now