I'm trying to find a way one can limit the length of the buffer for user input to the console. The reason for this is because I've been putting together a program (Or, well, a text based game library) which has a line within a UI for user commands (For example: Unlock chest). I'm hoping to find a way to limit the length of this input otherwise the user will be able to keep typing out over the rest of the UI.
So in a nutshell: I'm looking for a way to limit string input length to 24 cells. On reaching the 24th cell, the cursor stops moving and thus disallows the user to type further.
Note: I'm using windows libraries, so I don't need an OS independent method.
http://cplusplus.com/forum/articles/28558/ !
As for the problem, I doubt there is a simple way. This is not something console is supposed to do. You could maybe write your own input functions to deal with that.
The reason why I've started with making a console based game is entirely for the purpose of learning about the more in-depth mechanics of console operation. It requires me to build my own functionality almost entirely from scratch. I'm not one that simply wishes to code a game, but rather I'm trying to understand how things work. I've already got functionality for cursor movement, text color, screen clearing, screen clearing based on cell color, getting character information, word wrapping in a message box that doesn't wrap mid-word, etc. (And no, I havn't used System() anywhere, Duoas ;) )
I'm well aware that by using OpenGL or DirectX I can much more effectively put together a text based game, but because they handle a lot of the functionality for me I won't really get much experience in the way of what goes on behind the scenes just to get a simple UI working, for example. At some point in the future, I even plan on writing a simple program to interface with the GPU and display a basic image, just so I can have some experience in how that's done.
I've already been thinking of various ways that I might be able to get around this current text input problem I'm having, thanks for your response. :)
Edit: Alright, I came up with a solution. I took input one by one via _getch() and a counter then put it into a string when enter is pressed. (There's more to it than that, but that's the basic idea.)