Menu Program, Input string - c++

I'm trying to create C++ menu program that does a lot of things such as count bytes, lines, words in a file.
I did all that. But what I could not do is to accept an mixed cases from the user. For example, if the user input "countbytes" the program will run but if he entered "CouNt Bytes" the program will not run.
So how could I do it?

If you do not want to change the logic that you have already developed, an easy solution is to take the input from the user and convert it into lower case. Then process it.

Related

Prompt user to fill in a template?

I've never been able to find anything about this in any language, but what I want to do seems rather simple to me.
I want to prompt the user for input, but have them fill in a sort of template. Let's use a simple DD-MM-YYYY date as an example.
[█ - - ]
█ is where the user writes.
As they write, the [ and - stay where they are, with the cursor jumping past them, and hitting enter submits.
I'm not expecting anyone to write all of this for me, but cin and cout seem to be too crude a tools to do this, and so I'm wondering where I should even start, if not there.
Is there something that already does this, or at least something that gives me more control of the cursor to allow me to write it myself?
I do not want to be drawing a full-on TUI with windows and boarders and colors, so ncurses would just get in the way. I just want a single-line text field that returns the input.
EDIT: The most promising non-ncruses alternative for a helpful library seems to be Terminal.
Generally what you want is a text-based GUI library, such as ncurses. Doing console work is platform-specific, and every system has its own console API to do this. If you want to implement this yourself, you would have to examine what options does your target operating system give you in terms of console API, and build a custom solution based on that.

Ways to make one line in console window disappear after a couple seconds?

I need to basically flash a set of numbers for roughly 2 seconds. The user will then have to remember the numbers and type them. How can I do this? I have tried to use a timer or changing the color of the text to the same color of the background, but I can't think of a better way of doing so. Any suggestions?
You have basically three ways of handling this, because typical terminals don't have have the concept of a "screen", just lines.
Use carriage return or backspace characters to overwrite previous characters with blank spaces (but note the user can hit Enter to "preserve" the data in this case).
Print out a bunch of empty lines afterwards, but the user can scroll back.
Use a curses library of some kind (probably ncurses).
You'll need to look at the choices and see which is the best fit for exactly what you are trying to achieve.

Restarting a program with a key word - re looping?

So I've made a program in class for a project, this is done using C++, which is a menu system with one sub menu, to then deliver correct directions from one location to another,
this involved many else and if statements as well as a while loop. however, i'm wondering if it is at all possible to make it so if the user enters a particular string, to restart from the beginning of the program? such as a small function which is a re director to the top of the code again? so if the user messes up on the first menu, they can type 'back' in and go back to the previous menu?
it sounds easy, and its simple, but i'm having trouble with it, and don't know what the best way to approach this would be, despite how minor it is!
Any help is appreciated
thanks!

prepopulate cin before reading it

I am writing a program in C++ (in Borland C++ builder 6.0) that reads and displays customer data through cin and cout and stores and reads it to and from a database (sqlite).
It uses a console for interaction with the user.
What I want to achieve is that the user can update customer data that has been written previously into the database (e.g. data like name, address, etc)
When the user is going to update customer data, I want to let him go through the same steps/data as when creating a customer, but now, the data that the user wants to enter or modify has been prepopulated (as read from the database) and already displayed on the console, i.e. written into the input buffer cin, like it was typed in by the user. The user then only needs to hit enter to go to the next step/data and leave the data as it was. If the user needs to change or updata the data, he needs to change the data that was read from the database and displayed, but can modify it as he likes after which it will be written/updated into the database.
I hope it's clear what I mean.
This can't be done (trivially - almost anything CAN be done if you just put enough effort into it, the trick is to know when to put the effort on doing it a better way!) with cin/cout. You are much better off using some sort of text-mode UI library, such as ncurses or similar.
I have written a lot of code that did something similar, but I wrote my own set of functions to manage cursor position, input of data with validation, selecting things from lists, etc, etc. You will probably have to do SOME of that.
I would also suggest that you at least consider using a more modern compiler.

supplying inputs to stdin programatically line by line?

I have a test program which prompts for input from user(stdin), and depending on inputs, it asks for other inputs, which also need to be entered.
is there a way I can have a script do all this work ?
There's a program called expect that does pretty much exactly what you want -- you can script inputs and expected outputs and responses based on those outputs, as simple or complex as you need. See also the wikipedia entry for expect
I may have misunderstood, but do you have a program which reads the input and does something with it, and you just want to know how to automate providing it some test input?
For a given test case, does the input you provide have to depend on the output from the program, or is it the same every time?
If the input for a given test is the same every time, then just put it in a text file and redirect stdin for your program to read from that file:
myprogram.exe < input.txt
If the input is different each time, for the same test, then this doesn't help. But for a typical simple test, you just want to answer "y" to the first question, "n" to the second, and "hello world" to the third, or whatever.
In the general case, yes, there is.
For more specific tasks, you can get other tools to do the job that will be more specialized and usable for that particular task.