Give output to child process

I'm trying to build a basic shell for Unix.
This is the code I use to create a new process:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
pid = fork();
if (pid == 0) {
	setpgrp();
	complexCommand(argv, isComplex);
	}
else if (pid == -1) { //ERROR
	cout << "smash error: > Creating new process failed. Terminating smash..." << endl;
	exit(1);
}
else {
	jobs.push_back(jobType(argv[0], pid));
	if (argv.back().compare("&")) {
		fgPid = pid;
		int result;
		wait(&result);
	}
}

Where complexCommand is a function that handles the command (uses execvp after generating the correct string out of argv).
My problem is that after if while in the shell I use a program that needs to print to the screen and handle input, it doesn't work as expected.
To test this, I built this small program:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main() {
	int x1, x2;
	do {
		cout << "Enter 2 numbers\n";
		scanf("%d %d", &x1, &x2);
		cout << x1 << " + " << x2 << " = " << x1+x2 << ".\n";
	} while (1);
	return(0);
}

And when I use the shell I built to run it, the output is only "Enter 2 numbers" for one time. It doesn't print the result, or anything else.
Is there anything I need to do in the parent process (my shell in this case) to give the child the output?

Thanks.
setpgrp(); ¿what is this for?
man wrote:
If setpgrp() creates a new session, then the new session has no controlling terminal.
Checkout tcsetpgrp()
Topic archived. No new replies allowed.