+ 1

How can I calculate the length of any screen without first knowing how many spaces it has from left to right?

I have created a function in language C that receives a string and then writes it centered on the next line of the screen, but first I must count and define how many spaces has the screen I'm using. For example, (assuming 80 spaces or colums on screen) if the string is "JAVA", which has 4 letters, 38 spaces will be written before it. Is it possible to detect the length of the screen in use through a function? Attached here my code: https://code.sololearn.com/cUhPiac90e3n/?ref=app

19th Sep 2017, 12:47 AM
zhoolf
zhoolf - avatar
4 ответов
+ 2
I googled and it looks like you can run the "mode" command in the command prompt to figure out it's size!
20th Sep 2017, 12:54 AM
Schindlabua
Schindlabua - avatar
+ 3
Short answer is: You can't Longer answer: You can assume that most terminals are 80 characters wide, that's pretty much the standard everywhere (because punchcards from the 50s and earlier had 80 holes!). On Windows you need to go into some options to change that and nobody ever does it, on most Linuxes you can't make it smaller than 80 either if I remeber correctly? Bonus answer: If you *really* need to know and don't care about Linux or Mac, you may get lucky in the windows registry. The command prompt stuff is stored in HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor and I guess you'll also find the width there (I'm not on PC at the moment to check though).
19th Sep 2017, 2:01 AM
Schindlabua
Schindlabua - avatar
+ 1
@Schindlabua thanks for your time! I'm going to try it now!
20th Sep 2017, 1:27 AM
zhoolf
zhoolf - avatar
0
Thanks so much @Schindlabua ! especially for the longer answer. x) I have been looking for that path in the Windows registry, but I haven't found anything that refers to the window width property, I don't know if it will have to do with a permissions issue or that access to that property is hidden in my Windows. Or maybe I should look for more in other paths. 😅 Also, I want to navigate the Win32 API, in case I find something that can help me with my problem.
20th Sep 2017, 12:12 AM
zhoolf
zhoolf - avatar