I am working on creating a UNIX shell for a lab assignment. Part of this involves storing a history of the past 10 commands, including the arguments passed. I'm storing each command as a C++ string, but the parts of the program that actually matter, and that I had no input in designing (such as execve) use char * and char ** arrays exclusively.
I can get the whole command from history, and then read the program to be invoked quite easily, but I'm having a hard time reading into an arguments array, which is a char *[40] array.
Below is the code for a program I wrote to simulate this behavior on a test string:
#include <sstream>
#include <iostream>
#include <string>
using namespace std;
int main()
{
   char *chars[40];
   string test = "Hi how are you";
   stringstream testStream;
   testStream << test;
   int i = 0;
   while (true)
   {
      string test_2;
      testStream >> test_2;
      if (testStream.fail())
      {
         break;
      };
      chars[i] = (char *)test_2.c_str();
      i++;
   }
   for (int i=0; i < 4; i++)
   {
      cout << chars[i];
   }
   cout << "\n";
}
I get the feeling it has something to do with the array being declared as an array of pointers, rather than a multi-dimensional array. Am I correct?
 
    