I use forkpty(), with no problems. Unfortunately, I can't remember what documents I used to figure out how to use it. But I can offer a relatively short program for your perusal. I use that program all the time to pick up mail landing in an Unix shell account I have with my ISP. Part of that involves using telnet in an automated fashion; since it's not as easy as it looks to modify the telnet client source code, I figured that using a pty was the best way to go. Part of the processing over the pty takes place with the telnet client, and part of it does not.
The program is here, and I'll leave it here through February of 2007:
http://www.panix.com/~wje/wiwohefi/getmale.c
It's fairly straightforward, with a few necessary wrinkles you may not have thought of. There are also a few unnecessary wrinkles, like checking the status code after pseudo-running a shell command, that you might find useful.
Start looking at it by reading the main() function, which is at the end. The other functions are in alphabetical order.
The program logs in thrice.
The first time is on my local machine. You may wish to examine this because you'll need to log in when you use a pty.
The second time is through telnet to my ISP. That code is similar, and you probably won't be interested in looking also at that. If you are, I run telnet by using a script of my own called "pnx", which you'll find that I invoke in main(). That script is simply a helping shortcut. You'd just use the telnet command.
The third time is through ftp to my ISP.
Another wrinkle of note is that when you want to send a <return> down the pty, \r works. I haven't tried \n, but \r is exactly what goes through your keyboard when you use the <Enter> key (or <Return> key, depending on your keyboard), so I'd stick with \r if I were you.
You will also be interested in examining the use of tcgetattr(), tcsetattr(), and select(), especially if you may not have used those functions yourself.
Anyway, take a look at the program and come back here if you have any questions.
Hope this helps.