Screen is already installed on most distros. I'm unsure from your previous post but it seems like you don't want to use screen and want to embed the code into your program? Or maybe your not understanding exactly what screen is. In your terminal just issue the command
where PROGRAM= any linux program that hangs and waits for user input. For example try
Do what you want in nano hit CTRL+a+d to hop out of it and
to resume where you left off. If you finished the rest of your terminal program you could try using screen on that to see if it behaves the way you want it to.
If you really insist on coding the detach and attach functionality yourself, my only guess is that you'll have to use fork() in order to send the program to the background. Try googling "c fork detach". I still think your better off using screen, unless this is some sort of school assignment or something for work. Good luck, hope you don't end up reading the source code because it is nasty