here is the problem:
Write a C/C++ program (call it string invert) that takes a
string argument from the command line and outputs the string in reversed order. Here comes
the twist: Each process can output at most one character. If you want to output more than a
single character, you must fork off one or more processes in order to do that, and each of the
forked processes in turn outputs a single character. After the call to program string invert
with the command line argument, the output should appear, and no more processes should
be running, in addition to the shell. Test your program on any UNIX/LINUX machine, and
turn in the source code as part of the written assignment.

and i really dunno how to use fork to make this work, should I recursive call the function to make this work? or by creating more child processes? I am really new to this fork function and have no idea how to really apply it in this situation, so please help me!!! thank you!

#include <stdio.h>      /* needed for printf() and fprintf() */ 
#include <stdlib.h>     /* needed for EXIT_FAILURE/EXIT_SUCCESS */ 
#include <string.h>     /* needed for strerror() */ 
#include <unistd.h>     /* needed for fork() and getpid() */ 
#include <sys/types.h>  /* needed for pid_t */ 
#include <iostream>

using namespace std;

string result;
void print(string s){
	pid_t pid;
	pid = fork();
	if(pid == 0){
	else if (pid < 0){
	return 0;
int main(){
	string s;
	cout<<"enter string you want to invert\n";
5 Years
Discussion Span
Last Post by DeanMSands3

Dead thread is dead. Leave dead thread dead.

On the subject of how to go about doing this there's a few different ways:
A. Use pipes.
B. Use sockets.
C. Use environment variables.
D. Use shared memory.

Also, the OP didn't realize the word would be passed as a parameter on the command-line instead of reading in with a prompt.
Admittedly, this is one of the few times where I've read an entire first post instead of skimming it. (I've gotten in trouble for that.)

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.