I'm working on a program that, among other things, simulates a command line interface. I've got my code set up such that the first word in the line that a user enters dictates which action will take place and the remaining words/text are simply parameters. My goal was to have each of these words/parameters read into a string pointer. The problem I've run into is that if I can't use string pointers to do standard string functions, i. e. normally you can do something like
aString[1]
will return the second character in a string. However, if
aString
is a pointer, the following won't work.
myString = *aString[1];
This apparent lack of functionality is causing me much frustration. I'm trying to get my program working elegantly and efficiently. I really like the idea of reading each parameter into its own (temporary) variable as opposed to one big long string, then pulling out what I need manually. Is there a way to return specific characters in a string if that string is only accessed through a string pointer or an array of string pointers? Or do I have to make a long list of string variables that get cleared after every action?
Here's a general idea of how I wanted this process to work.
1 2 3 4 5 6 7 8 9 10 11
|
string* param[10];
//while there is data, keep making new strings and assigning values to them...
int paramNum = 0;
while (cin.peek() != '\n')
{
param[paramNum] = new string;
cin >>*param[paramNum];
paramNum++;
}
|
EDIT: To be more specific about what this portion of my program is trying to do, I want the user to be able to type in
count epic
and get a result that shows how many times the word "epic" occurs in the document. However, I also want them to be able to type in
count "Stephen is awesome"
and be able to search for the entire phrase "Stephen is awesome" (he really is). To do this, I need to be able to see whether or not there are quotation marks in the string the user entered. In order to do that using the method I want to (string pointers) I need to be able to check individual characters in a string.