I am working on embedded system using C and linux. User can connect to the device via SSH or a console serial cable. He can do this through PuTTY o
A serial line does not have a way to negotiate the size of the terminal. Running a real xterm et.al. over a TTY/PTY device pair uses the TIOCSWINSZ/TIOCGWINSZ ioctl() pair to pass this information.
Traditionally, this information was kept in termcap or terminfo about the real physical piece-of-glass-with-phosphor-coating terminals such as a DEC VT220. This is a static fixed database of values known ahead of time, which was correct around the time that a "terminal" literally was this fixed piece of hardware, but doesn't work so well in modern times of terminals being just some piece of program that draws to a framebuffer or similar.
I'd suggest the best method would be to try TIOCGWINSZ, if that fails use terminfo's tgetnum("co"), and if that fails just presume 80x24.