Hi,
How can I know the number of lines of the screen when working in a text environment (non X Windows).
Thanks in advance
Hi,
How can I know the number of lines of the screen when working in a text environment (non X Windows).
Thanks in advance
You can't - in standard C anyway.
You could try using a library like ncurses, but that adds quite a bit to your code.
First question is, why do you want to know?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Without messing around with terminal calls, most modern unix shells
(POSIX (sh) and Korn (ksh) ) support the LINES variable
A crude hack:
This is not something to call repeatedly, it creates a process, so is slowCode:#include <stdio.h> int MAX_LINES(void) // number of terminal lines { char tmp[24]={0x0}; FILE *p=popen("echo $LINES","r"); fgets(tmp,sizeof(tmp),p); return atoi(tmp); }
moi - yes.