C++ wants you to use a constant for an array size. If you want to do dynamic memory allocation then lookup new and delete
for (int a=0;a<=TempNumOne;a++)
This for loop will iterate 1 past the number of elements needed
When you pass val to cout you're passing the memory address. * is used to dereference the pointer so you can pass what it's pointing to.
This is not the intended purpose of strncpy. You're passing it y as the source string which is just a single char and telling it to copy KEYWORK_MAX_LEN-1 elements from a single char to word. If you just want to set the first element of word to y then a simple assigment will do. word = y;
Ignore everything that was commented out from my code in the first post. By commented out, I mean code after " //"
I want to pass an equivalent of char* argv[ ] to my strncpy. Earlier in the code, it was passed through optarg, but I am not in main anymore and the value of "optarg" will be determined by me.
1 2 3 4 5
case's': //optarg is the keyword passed after s- optarg. i.e. the value is stored in optarg
cout<<"\noptarg is "<<optarg<<"\n";
strncpy(word,optarg,KEYWORD_MAX_LEN-1); //copies the first (KEYWORD_MAX_LEN-1) characters of optarg to word
doSearch = true;
Basically, I want to implement the same, but with an arbitrary optarg outside of code main.
BTW, word is:
cout<<"search method about to exec";
rcode = search(word);
cout<<"\nNow, enter -1 to quit\n";// or word to continue\n";
cout<<"\nenter new word\n";
cout<<"\nmystring is: "<<my_stringC<<"\n";
cout<<"str copy about to exec with myStringC = "<< my_stringC; //this doesnt execute
The cursor gets lost in the line before the last. It never executes that code.
enter -1 to end loop. otehrwise word to search
server says 'thnking' was *NOT* found.
server's answer was verified.
search method about to execinside search method
Now, enter -1 to quit
enter new word
mystring is: hello