Linux fork, execv, wait question

Hi All,

I have a program for class that needs to do the following:

  1. Print the directory entries from the current directory using ncurses
  2. Provide a prompt next to each directory entry and allow the user to enter commands that may or may not be about the file
  3. Execute those commands in sequence

My question is this:
How can I use fork, execv, and wait to allow for commands that also use ncurses or stdin/stdout to do what they need to do and then restore my ncurses program.

Example:

Say I want to execute "ls /etc/ | more". If I use system() the output is jumbled like this:

How do I make it so that when I press ENTER, the output of more is exactly as you would see it if you opened the terminal and typed it, and then after more terminates, my ncurses program reappears as if nothing happened.

It seems like if I were to use execv it would accomplish what I want because from the man pages: "The exec family of functions replaces the current process image with a new process image." If I were to replace a child process image with the process image of "more", it should achieve what I want correct? Can anyone please provide me with some insight?

Thanks for reading

Please post this in the homework forum. Thank you.