Question: Using onlinegdb.com, please explain how to get the outputs, and please show screenshots of how to get the output, I have the code below, i
Using onlinegdb.com, please explain how to get the outputs, and please show screenshots of how to get the output, I have the code below, i just do not know how to get the outputs needed.
What to do
Write a C program mywrite whose behavior resembles that of the system command write.
mywrite accepts the following parameters:
$ mywrite terminal
where text messages are being sent to another terminal.
mywrite operates by copying lines from stdin of your terminal to stdout of the username's terminal.
Every line typed by the sender must be displayed at the receiver's terminal immediately after the sender
presses the Enter key or closes the connection.
The first line to be displayed on the other terminal must include a greeting message similar to this:
Message from another terminal...
When the user who started mywrite presses CtrlD EOF mywrite closes the connection and displays
the final message on the other terminal:
mywrite must implement a filtering mechanism based on the following list of keywords: apple, pear,
banana, plum. If one of these keywords appear as a part of the input line, mywrite will produce a
relevant warning on the senders terminal and will not send that line to the receiver. Here's an example of
an input line and a corresponding warning:
I like bananas!
You entered a prohibited word: banana. Your message will not be sent.
What to submit?
A single C source code file with your work.
Several screenshots in PNG or JPG format showing two parallel terminal sessions with mywrite
message exchange.
code:
#include
#include
#include
#include
#include
#define MAXLINE
List of prohibited keywords
const char keywordsapple "pear", "banana", "plum";
const int keywordcount ;
Function to check if a message contains a prohibited word
int containsprohibitedwordconst char message
for int i ; i keywordcount; i
if strstrmessage keywordsi NULL
return ;
return ;
int mainint argc, char argv
if argc
fprintfstderr "Usage: s terminal
argv;
exit;
Open the target terminal for writing
int fd openargv OWRONLY;
if fd
perroropen;
exit;
char bufferMAXLINE;
printfMessage from another terminal...
;
Read lines from stdin and write to the terminal
while fgetsbuffer MAXLINE, stdin NULL
if containsprohibitedwordbuffer
fprintfstderr "You entered a prohibited word. Your message will not be sent.
;
else
if writefd buffer, strlenbuffer
perrorwrite;
closefd;
exit;
Close the connection when EOF is encountered
printfConnection closed.
;
closefd;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
