Question

Write a C or C++ program A8p1.c(pp) that accepts one command line string parameter. Call the...

  1. Write a C or C++ program A8p1.c(pp) that accepts one command line string parameter. Call the fork function to produce two processes. In the child process print out the lower case version of the string. In the parent process print out the reversed upper case version of the string (e.g. child: “abc”; parent: ”CBA”). You may call the toupper and tolower functions in the header <ctype.h> if you wish. Specify in the output whether the parent or child process is printing. Submit code source file, not screen shots.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <sys/types.h> 
#include <unistd.h>
#include <ctype.h>  


void printLower(char *s) {
        int i = 0;
        while(s[i] != '\0') {
                printf("%c", tolower(s[i++]));
        }
        printf("\n");
}

void printUpperRev(char *s) {
        if(s[0] == '\0') {
                return;
        }
        printUpperRev(s + 1);
        printf("%c", toupper(s[0]));
}

int main(int argc, char *argv[]) {

        if(argc < 2) {
                printf("Error! enter a command line parameter.\n");
                return 0;
        }

        int pid = fork();

        if(pid == 0) {
                // child process
                
                printf("In child process: ");
                printLower(argv[1]);

        } else {
                
                printf("In parent process: ");
                printUpperRev(argv[1]);
        printf("\n");
        }
}


Please upvote, as i have given the exact answer as asked in question. Still in case of any issues in code, let me know in comments. Thanks!

Add a comment
Know the answer?
Add Answer to:
Write a C or C++ program A8p1.c(pp) that accepts one command line string parameter. Call the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT