Question: HALmod.h below.. HALmod.cpp below #include HALmod.h int getCommand(string tokens[]) { string commandLine; bool commandEntered; int tokenCount; do { cout ; while (1) { getline(cin, commandLine);
![HALmod.h below.. HALmod.cpp below #include "HALmod.h" int getCommand(string tokens[]) { string](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f0864a612a2_04966f08649c29c4.jpg)

HALmod.h below..

HALmod.cpp below
#include "HALmod.h"
int getCommand(string tokens[])
{
string commandLine;
bool commandEntered;
int tokenCount;
do
{
cout ";
while (1)
{
getline(cin, commandLine);
commandEntered = checkForCommand();
if (commandEntered)
{
break;
}
}
} while (commandLine.length() == 0);
tokenCount = tokenizeCommandLine(tokens, commandLine);
return tokenCount;
}
int tokenizeCommandLine(string tokens[], string commandLine)
{
char *token[MAX_COMMAND_LINE_ARGUMENTS];
char *workCommandLine = new char[commandLine.length() + 1];
int i;
int tokenCount;
for (i = 0; i
{
tokens[i] = "";
}
strcpy(workCommandLine, commandLine.c_str());
i = 0;
if ((token[i] = strtok(workCommandLine, " ")) != NULL)
{
i++;
while ((token[i] = strtok(NULL, " ")) != NULL)
{
i++;
}
}
tokenCount = i;
for (i = 0; i
{
tokens[i] = token[i];
}
delete[] workCommandLine;
return tokenCount;
}
// Do not touch the below function
bool checkForCommand()
{
if (cullProcess)
{
cullProcess = 0;
cin.clear();
cout
return false;
}
return true;
}
// This is a very paired down version of Dr. Hilderman's function
int processCommand(string tokens[], int tokenCount)
{
if (tokens[0] == "shutdown" || tokens[0] == "restart")
{
if (tokenCount > 1)
{
cout
return 1;
}
cout
cout
return 0;
}
else
return 1;
}
Part 2-Extend the Code We want to be able to tum the tokens array into an array of c strings (In other words, in the format of char **). Build the following functions and call them from main: - char ** convertToC (string tokens [], int tokenCount); - This converts the tokens into a c version of an array of words and returns the pointer to that array - void cleanupcarray (char ** cTokens, int tokencount); - This cycles through the c string version of the array and frees up any memory that has been allocated - void printReverse (char k cTokens, int tokencount); - This cycles in reverse through the c string version of the words and prints each word A sample run might look something like the following When you run your code through valgrind using: valgrind --leak-check=yes ./demo A message like the following should be displayed: \#include "HALmod. h" int main() \{ string tokens[MAX_COMMAND_LINE_ARGUMENTS]; int tokenCount; do \{ | tokenCount = getCommand(tokens); return 0; \#include \#include \#include \#include \#include \#include using namespace std; // The following two lines come from HALglobals.h const int MAX_COMMAND_LINE_ARGUMENTS = 8; const int SLEEP_DELAY =100000; int getCommand(string tokens[]); int tokenizeCommandLine(string tokens [], string commandLine); bool checkForCommand(); int processCommand(string tokens[], int tokenCount); static volatile sig_atomic_t cullProcess = 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
