Question: I am starting to write a command line converter and the only concern I have is user input (rest wont be hard). The program will have few commands like (convert 2 m to km), so when the user enters that, the program will output the converted value. My question is, what is the best way to parse user input and determine the command that user entered?. Should I divide user input into array of words and then pass to a function, so it can do something or there is another way?

Answer: 
I have written a few types of "simple parsers" (and several more advanced ones). From what you describe, if the commands are "convert 2 m to km", then you would simply need to split things on spaces. 

Of course, if you allow "convert2mtokm" and "convert 2m to km" it gets a bit more difficult to deal with. Sticking to a "strict rule of there has to be a(t least one) space between words" makes life a lot easier. 

At that point, you will have a `vector<string> cmd` that can be dealt with. So for example:

```
if (cmd[0] == "convert")
{
    convert(cmd); 
}

... 

void convert(vector<string> cmd)
{
    double dist = stod(cmd[1]);
    string unit_from = cmd[2]; 
    string unit_to = cmd[4]; 
    if(cmd[3] != "to")
    {
         ... print some error ... 
    }
    double factor = unit_conversion(unit_from, unit_to);
    cout << "that becomes " << dist * factor << " in " << unit_to << endl;
}

```
An array of structures will be fine. The structure may be like this:

```
struct cmd
{
    char **usrcmd;
    void (*fc)();
};

```

Then you just have to iterate the array and compare the user input and the usrcmd[0] field (I assume the command is the first word).

However this solution is not the best way to go if you have a lot of user commands to handle.