Ok, two questions.
first of all
Q1. I allocated sufficient memory at run time, still after running case 6 two times in a row, the s1 prints garbage, and on running case 6 for a third time the value of s1 disappeared
the first image shows the garbage value at the end of string
[the second image shows the string 1 has disappeared][2]
Q2. the STCPY( COPY FUCTION) is not working properly, its showing segmentation fault, but again, I reallocated sufficient memory.( I need to copy s2 to s1, so I reallocated L2(string 2's length) to s1 so that there won't be memory wastage)
segmentation fault
here's the code:
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int STRLEN(char* S){
int i=0;
while(S[i] != '\0'){
i++;
}
return i;
}
int SUBSTR(char* str1, char* str2){
//string str1;
//string str2;
int L1=0,L2=0;
int i,j,flag=0;
int count=0;
/*cout<<"\nEnter main string greater characters(str1) : ";
cin>>str1;
cout<<"\nEnter phrase to find (str2) : ";
cin>>str2;
*/
L1 = STRLEN(str1); //calculate legth of strings
L2 = STRLEN(str2);
for(i=0;i<L1;i++){
count = 0;
flag = 0;
for(j=0;j<L2;j+=1){
if(str1[i]==str2[j])
{
//good
if(j==L2) //successful phrase's each character
traversed
{
break;
}
i++;
count++;
//j++;
}
else
{
break;
}
} //terminate inner for loops
{
i -= count; //i was incremented explicitly in
inner loop. for normal operation,
} // i has to be decremented by equal
no. of increments in inner loop
if(j==L2) //flag for successful traversing of phrase 2
in string 1
{
flag = 1;
break;
}
}
if(flag == 1)
{
cout<<"\nSUBTRING PRESENT AT "<<(i+1);
}
return 0;
}
int STREQL(char* str1, char* str2){
int flag = 0;
int L1=0,L2=0;
int i,j;
int count=0;
/* cout<<"\nEnter first word : ";
cin>>str1;
cout<<"\nEnter second word : ";
cin>>str2;*/
char* p1;
char* p2;
p1 = str1;
p2 = str2;
while(*(p1) != '\0')
{
if(*(p1) == *(p2))
{
//good
p1++;
p2++;
}
else{
flag = 1;
break;
}
}
if(flag == 1 )
{
cout<<"\n STRINGS ARE NOT EQUAL";
}
else{
cout<<"\n STRINGS ARE EQUAL";
}
return 0;
}
int STCPY(char* s1, char* s2){
int L2 = STRLEN(s2);
int L1 = STRLEN(s1);
cout<<"\nPASS 1";
char* s3 = (char*)realloc(s1,L2); //Note :- s3 and s1 point to
same memory location
cout<<"\nPASS 2";
while(s2 != '\0')
{
*s3 = *s2;
s3++;
s2++;
}
cout<<"\nPASS 3";
s3 -= L2;
s2 -= L2;
cout<<"\n STRING 1 = "<<s1;
cout<<"\n STRING 2 = "<<s2;
return 0;
}
int STRREV(){
return 0;
}
int STRLEN(char* str1, char* str2){
int L1=0,L2=0;
L1=STRLEN(str1);
L2=STRLEN(str2);
cout<<"\nSTRING 1 LENGTH = "<<L1;
cout<<"\nSTRING 2 LENGTH = "<<L2;
return 0;
}
int STRCAT(char* s1, char* s2)
{
int L1=0,L2=0;
int i,j;
L1=STRLEN(s1);
L2=STRLEN(s2);
//cout<<"\nSTRING 1 LENGTH = "<<L1;
//cout<<"\nSTRING 2 LENGTH = "<<L2;
char* s3 = (char*)realloc(s1,(L1+L2));
int cnt=0;
for(i=L1,s3 = s3+L1; *s2 != '\0'; i++)
{
*s3 = *s2;
s2++;
s3++;
cnt++;
}
s3 = s3-cnt-L1;
s2 = s2-cnt;
//cout<<"\nConcatenated string s3 = "<<s3;
//cout<<"\nConcatenated string s1 = "<<s1;
cout<<"\nSTRING 1 = "<<s1;
cout<<"\nSTRING 2 = "<<s2;
return 0;
}
int main(){
int i,j,choice;
char* s1;
char* s2;
cout<<"\nEnter string : ";
s1 = (char*)malloc(50);// ok i made this 50 bytes instead of 10
cin.getline(s1,50); // cause u guys arguing, but still that doesn't change the output
//cout<<s1;
cout<<"\nEnter string : ";
s2 = (char*)malloc(50);
cin.getline(s2,50);
//cout<<s2;
cout<<"\n------------MENU------------";
cout<<"\n1.SUBSTRING FIND";
cout<<"\n2.EQUAL CHECK";
cout<<"\n3.COPY STRING";
cout<<"\n4.REVERSE";
cout<<"\n5.STRING LENGTH";
cout<<"\n6.STRING CONCATENATION";
cout<<"\n7.EXIT";
cout<<"\n----------------------------";
do{
cout<<"\n\nEnter your choice : ";
cin>>choice;
switch(choice)
{
case 1:
SUBSTR(s1, s2);
break;
case 2:
STREQL(s1, s2);
break;
case 3:
STCPY(s1, s2);
break;
case 4:
STRREV();
break;
case 5:
STRLEN(s1, s2);
break;
case 6:
STRCAT(s1, s2);
break;
case 7:
break;
}
}while(choice != 7);
return 0;
}
Replace everything under "PASS 2" log to this:
while(*s2 != '\0')
{
*s3 = *s2;
s3++;
s2++;
}
Observe that s2 != '\0' means basically: s2 != nullptr which is never true. That's why you get segmentation fault.
A C string is ended with a final \0. So the memory footprint is strlen(str) + 1 byte.
The problem with your STRCAT function is that you forgot to add space for the final \0 (s3 = realloc(s1, L1+L2 +1), and you also forgot to add the final \0 (s3[L1+L2] = 0).
idem for your STCPY function, + s2 != 0 to replace with *s2 != 0
Related
So writing a palindrome with pointers and boolean. I have it working with a single word but then I began building it to work with a sentence. The problem is I am unsure how to keep the new modified sentence after making it lowercase and getting rid of the spaces for it to return whether it is or isn't a palindrome. It keeps returning the palindrome as false and when I went to check why I see that the program ignores the modification and kept the original string. I can't use "&" on the parameter as I tested it out. Any hints or takes on what I can do to keep the new modified string?
int main()
{
userInput();
return 0;
}
void userInput()
{
char str[90];
std::cout<<"Please enter a string to check if it is a palindrome: ";
std::cin.getline(str, 90);
modifyString(str);
}
void modifyString(char *string)
{
int count = 0;
for (int i=0; i<strlen(string); i++)
{
putchar(tolower(string[i]));
}
for (int i = 0; string[i]; i++)
{
if (string[i] != ' ')
{
string[count++] = string[i];
}
}
string[count] = '\0';
std::cout<<string<<std::endl;
results(string);
}
bool checkPalindrome(char *string)
{
char *begin;
char *end;
begin = string;
end = (string + strlen(string)-1);
while(begin != end)
{
if ((*begin) == (*end))
{
begin ++;
end--;
}
else
{
return false;
}
}
return true;
}
void results(char *string)
{
bool isItPalindrome;
isItPalindrome = checkPalindrome(string);
if( isItPalindrome == true)
{
std::cout<<"\nCongrats, the string is a palindrome!";
}
else
{
std::cout<<"\nThis string is not a palindrome.";
}
}
For starters this definition of main
int main()
{
userInput();
return 0;
}
does not make a sense. According to the function name main the function should perform the main task that is to output whether the entered sentence is a palindrome or not.
This for loop
for (int i=0; i<strlen(string); i++)
{
putchar(tolower(string[i]));
}
does nothing useful. It just outputs the string in the lower case.
This statement
end = (string + strlen(string)-1);
can invoke undefined behavior if an empty string was passed.
This while loop
while(begin != end)
{
if ((*begin) == (*end))
{
begin ++;
end--;
}
else
{
return false;
}
}
also can invoke undefined behavior for a string containing an even number ofo characters because after this if statement
if ((*begin) == (*end))
{
begin ++;
end--;
}
if the two adjacent characters are equal then begin after incrementing will be greater than end after its decrementing. And as a result the loop will continue its iteration.
In general the approach when the original string is changed is just a bad approach.
Your program has too many functions. It is enough to write one function that will determine whether the passed string is a palindrome or not.
Here is a demonstrative program.
#include <iostream>
#include <cstring>
#include <cctype>
bool checkPalindrome( const char *s )
{
const char *t = s + std::strlen( s );
do
{
while ( s != t && std::isspace( ( unsigned char )*s ) ) ++ s;
while ( s != t && std::isspace( ( unsigned char )*--t ) );
} while ( s != t &&
std::tolower( ( unsigned char )*s ) == tolower( ( unsigned char ) *t ) &&
++s != t );
return s == t;
}
int main()
{
const size_t N = 100;
char s[N] = "";
std::cout << "Please enter a string to check if it is a palindrome: ";
std::cin.getline( s, N );
std::cout << '\n';
if ( checkPalindrome( s ) )
{
std::cout << "Congrats, the string is a palindrome!\n";
}
else
{
std::cout << "This string is not a palindrome.\n";
}
return 0;
}
Its output might look like
Please enter a string to check if it is a palindrome: 1 23 456 6 54 321
Congrats, the string is a palindrome!
Okay, I solved it!
As one of the users on here brought up a point that my lowercase did not modify the string and only prints it out. I try my best to solve the problem and I think I found the solution and everything works perfectly fine. comment back to debug it if you like to see how it looks but what I did was create a for loop again for the lower case but made another pointer with it. here how it looks.
for (char *pt = string; *pt != '\0'; ++pt)
{
*pt = std::tolower(*pt);
++pt;
}
Now that definitely changes the string into a lower case and keeps it as a lower case.
so now the modified function looks like this and ready to take any sentence palindrome you give it. Example: A nUt fOr a jAr of tUNa. We make this all lowercase and take out space and boom palindrome and return true.
void modifyString(char *string)
{
int count = 0;
for (char *pt = string; *pt != '\0'; ++pt)
{
*pt = std::tolower(*pt);
++pt;
}
for (int i = 0; string[i]; i++)
{
if (string[i] != ' ')
{
string[count++] = string[i];
}
}
string[count] = '\0';
//take out the forward slash below to see how it looks after being modified
// std::cout<<std::endl<<string<<std::endl;
results(string);
}
doing some exrecises for upcoming test. a bit stuck in this one.
"Write a program that asks the user for two strings and checks and prints a message if the second string is contained cyclic in the first string. The cyclic containment means that either the second string appears normally within the first string or the second string appears so that its prefix appears at the end of the first string and the continuation appears at the beginning of the first string".
You can assume that the strings contain only lowercase letters.
String functions are only allowed are : strlen, strcpy, strcmp, strcat
for example:
String A: itisaniceday
String B: sanic
Is a regular occurrence
String A: itisaniceday
String B: dayit
It's a cyclic occurence.
what I did so far:
#include <iostream>
#include <string.h>
using namespace std;
#define Max 128
int isCyclic(char* str1, char* str2);
int main()
{
char* str1 = new char[Max];
char* str2 = new char[Max];
cout << "Please enter two strings:" << endl;
cin >> str1 >> str2;
cout << isCyclic(str1, str2) << endl;
delete[] str1;
delete[] str2;
}
int isCyclic(char* str1, char* str2)
{
int s1 = strlen(str1);
int s2 = strlen(str2);
if (s1!=s2) // if string size is diffrent - they are not contained cyclic
{
return 0;
}
}
You will need two loops, first one over string 1 which is our starting point in string 1 for comparison and second one over string 2 which will be matched to string 1 in a cyclic way. If we reach the end of string 1 and still some characters are left in string 2 then cycle through string 1 starting from index 0.
#include <stdio.h>
#include <iostream>
#include <string.h>
// Should be avoided in general. Use scope resolution instead.
using namespace std;
char* isCyclic(char* s1, char* s2){
int s1_size = strlen(s1);
int s2_size = strlen(s2);
// s1 must contain s2
if(s2_size > s1_size)
return "No Occurence";
for(int i = 0; i < s1_size; i++){
int current = i;
// Boolean to track if we are currently cycling through s1
bool inCycle = false;
int j = 0;
for(; j < s2_size; j++, current++){
// character wise comparision
if(s2[j] != s1[current])
break;
if(! inCycle){
// start from first. Note that we are setting current = -1.
// as we will be incrementing it in the for loop.
if(current == s1_size - 1 && j < s2_size - 1){
current = -1;
inCycle = true;
}
}
}
if(j == s2_size){
if(inCycle)
return "cyclic";
else
return "regular";
}
}
return "No Occurence";
}
int main()
{
printf("Hello World\n");
char* s1 = "itisaniceday";
char* s2 = "dayitis";
cout<<"Occurence Type: "<<isCyclic(s1, s2)<<endl;
return 0;
}
Here is a solution for the second part of the problem (cyclic part). I simply go through all of the characters in the first string and checked if they are the beginning of a cyclic appearance of the second string.
To check that I used % (the modolu operation) if you don't know what it dose then you really need to learn it now.
Also I used bool instead of int because numbers are confusing (and cursed).
#include <iostream>
#include <string.h>
using namespace std;
#define Max 128
bool isCyclic(char* str1, char* str2);
bool isCyclic(char* str1, char* str2,int start);
int main()
{
char* str1 = new char[Max];
char* str2 = new char[Max];
cout << "Please enter two strings:" << endl;
cin >> str1 >> str2;
cout << isCyclic(str1, str2) << endl;
delete[] str1;
delete[] str2;
}
bool isCyclic(char* str1, char* str2) {
for(int i = 0; i < strlen(str1); i++) {
if(str1[i] == str2[0] && isCyclic(str1,str2,i)) {
return true;
}
}
return false;
}
bool isCyclic(char* str1, char* str2,int start)
{
int containingStrLen = strlen(str1);
for(int i = 0; i < strlen(str2); i++) {
if(str1[(start + i)%containingStrLen] != str2[i]) {
return false;
}
}
return true;
}
There are some things missing in this code still:
1) The first part of the problem (it can easily be derived from this code).
2) Some size validation such as making sure that str1 is bigger then str2 before using is cyclic. And that the strings are smaller then Max (I assume).
3) A proper result print.
Good luck in your exam :)
There's a simple trick : if you duplicate the string's prefix at its own end, the problem becomes a straight substring search as a cyclic match would be recomposed at the end. It also handles the corner case where the substring loops back on itself, such as "looploop" inside of "loop".
So here's how you'd do it in broken C-ish dialect:
bool containsCyclic(char const *string, char const *substring) {
std::size_t const stringLen = std::strlen(string);
std::size_t const substringLen = std::strlen(substring);
// Too long a substring wouldn't fit in the string
if(substringLen > 2 * stringLen)
return false;
// Concatenate `string` with its own substring-long prefix
char *const loopedString = new char[stringLen + substringLen + 1];
std::strcpy(loopedString, string);
{ // Partial reimplementation of std::strncpy(loopedString, string, substringLen)
char const *src = string;
char *dest = loopedString + stringLen;
for(std::size_t count = 0; count < substringLen; ++count)
*dest++ = *src++;
*dest = '\0';
}
{ // Partial and naïve reimplementation of std::strstr(loopedString, substring)
for(char const *start = loopedString; start < loopedString + stringLen; ++start) {
// Check if substring is present at this offset
char const *s1 = start;
char const *s2 = substring;
while(*s2 != '\0' && *s1 == *s2)
++s1, ++s2;
if(*s2 == '\0') {
// We found a complete match of substring inside loopedString
delete[] loopedString;
return true;
}
}
}
// No match found
delete[] loopedString;
return false;
}
And just for kicks, here it is in C++:
bool containsCyclicCpp(std::string const &string, std::string const &substring) {
std::string const loopedString = string + string.substr(0, substring.size());
return loopedString.find(substring) != std::string::npos;
}
See it live on Coliru (with tests!)
I am a beginner in solving algorithmic questions. Until now, I have only self-taught coding. So, I am not sure about the proper conventions.
I was trying to solve a question to reverse a string.There is some problem with the code but I am not sure what it is after debugging step-by-step.
class Solution {
public:
string reverseString(string s) {
int n = s.length();
string reverse;
for (int i=0;i<s.length();i++)
{
reverse[i] = s[n-1];
n=n-1;
}
return reverse;
}
};
Input: "Hello"
Output needed: "olleh"
My output: "olleh " (extra space)
Input: A man, a plan, a canal: Panama
Output: No output
I searched online for solutions. There were related to pointers. It would be great if someone helped me understand why this logic doesn't work and why using pointers is a better idea.
ALREADY GIVEN. CANNOT CHANGE:
string stringToString(string input) {
assert(input.length() >= 2);
string result;
for (int i = 1; i < input.length() -1; i++) {
char currentChar = input[i];
if (input[i] == '\\') {
char nextChar = input[i+1];
switch (nextChar) {
case '\"': result.push_back('\"'); break;
case '/' : result.push_back('/'); break;
case '\\': result.push_back('\\'); break;
case 'b' : result.push_back('\b'); break;
case 'f' : result.push_back('\f'); break;
case 'r' : result.push_back('\r'); break;
case 'n' : result.push_back('\n'); break;
case 't' : result.push_back('\t'); break;
default: break;
}
i++;
} else {
result.push_back(currentChar);
}
}
return result;
}
int main() {
string line;
while (getline(cin, line)) {
string s = stringToString(line);
string ret = Solution().reverseString(s);
string out = (ret);
cout << out << endl;
}
return 0;
}
As you create reverse, you have to pass the length of the string as an argument, else the created string will be of size 0. This could look like this:
string reverseString(string s) {
int n = s.length();
string reverse(n,'0');
for (int i=0;i<s.length();i++)
{
reverse[i] = s[n-1];
n=n-1;
}
return reverse;
}
Reversing a string is trivial. Just construct a new one from the reverse iterators:
std::string reverse_str(s.rbegin(), s.rend());
or
std::string reverse_str(s.crbegin(), s.crend());
Here's how I would write your function:
string reverseString(const string& s) {
return {s.crbegin(), s.crend()};
}
Try this out
class Solution {
public:
string reverseString(string s) {
//cout<<"inside func";
int n = s.length();
cout<<n<<endl;
char reverse[sizeof(char)*n];// reverse stores the reverse of original string s
int i= 0;
for ( i=0;i<s.length();i++)
{
reverse[i] = s[n-i-1];
}
return reverse;
}
}
int main()
{
string s,r;
Solution sol;
s= "hello";
r= sol.reverseString(s);
cout<<r<<endl;
cout<<r.length()<<endl;
return 0;
}
when i= 0, n-i-1= n-1 which is the last element of the original string s. So the first element of the reverse string is the last element of s. Next i becomes i+1 i.e 1. This time second element of the reverse string is the last but one element in string s. This procedure is repeated till i < s.length(). The element to get copied is for index i= n-1 and n becomes n-(n-1)-1= 0, so the last element of reverse string is the first element of s. After this the loop exists. No additional extra characters are added.
i transform char* to char**. Each word must fold to array. But fold only first word.
input: "abc def 123"
out (expected): num ==3,arr == {"abc","def","123"}
out(real): num == 1,arr == {"abc"}
struct CommandArray
{
vector<char*> Arr;
USHORT Num;
};
CommandArray Text::StrToArray(LPSTR Str)
{
CommandArray Out;
LPSTR TempStr;
Out.Num = 0;
TempStr = strtok (Str," ");
while(TempStr != NULL)
{
Out.Arr.push_back(TempStr);
Out.Num++;
TempStr = strtok(NULL," ");
}
return Out;
}
strtok modifies its first argument (that's why it is a char* and not a char const*). One guess is that you do the same after the call to Text::StrToArray.
First. Use cin.getline(input,32); to get an input seperated by spaces, cin>>input won't work.
Concerning char* to char**. The code below folds each word into an array.
#include<windows.h>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
struct CommandArray
{
vector<char*> Arr;
USHORT Num;
};
CommandArray StrToArray(LPSTR Str)
{
CommandArray Out;
LPSTR TempStr;
Out.Num = 0;
TempStr = strtok (Str," ");
while(TempStr != NULL)
{
Out.Arr.push_back(TempStr);
Out.Num++;
TempStr = strtok(NULL," ");
}
return Out;
}
int main()
{
int ROWS=80; //80 characters wide
int COLUMNS=20;// 20 lines
int i;
char seperators[] = " ,\t\n";
char *token;
char* input_Dynamic1DCharPointerArray = new char[80];
char **output_Dynamic2DCharPointerArray = 0;
//memory allocated for elements of rows.
output_Dynamic2DCharPointerArray = new char *[ROWS] ;
//memory allocated for elements of each column.
for( i = 0 ; i < ROWS ; i++ ) output_Dynamic2DCharPointerArray[i] = new char[COLUMNS];
strcpy(input_Dynamic1DCharPointerArray,"apples 123 oranges 456 bananas 789 lemons 101112" );
//cout<<" \n";
//cin.getline(input_Dynamic1DCharPointerArray,32);
cout<<" \ninput = "<<input_Dynamic1DCharPointerArray<<" \n\n";
cout<<"Output = \n";
token = strtok( input_Dynamic1DCharPointerArray, seperators );
i=0;
while( token != NULL )
{
strcpy(output_Dynamic2DCharPointerArray[i],token);
cout<<output_Dynamic2DCharPointerArray[i]<<" \n";
token = strtok( NULL, seperators ); // C4996
i++;
}
cout<<" \n";
delete[] input_Dynamic1DCharPointerArray;
//free the allocated memory
for( i = 0 ; i < ROWS ; i++ )
delete [] output_Dynamic2DCharPointerArray[i] ;
delete [] output_Dynamic2DCharPointerArray ;
return 0;
}
I have this function sentanceParse with a string input which returns a list. The input might be something like "Hello my name is Anton. What's your name?" and then the return value would be a list containing "Hello my name is Anton" and "What's your name?". However, this is not what happens. It seems as if the whitespaces in the sentences are treated like a separator and therefore the return is rather "Hello", "my", "name" etc instead of what I expected.
How would you propose I solve this?
As I am not a 100% sure the problem does not lie within my code, I will add that to the post as well:
Main:
list<string> mylist = sentanceParse(textCipher);
list<string>::iterator it;
for(it = mylist.begin(); it != mylist.end(); it++){
textCipher = *it;
cout << textCipher << endl; //This prints out the words separately instead of the entire sentances.
sentanceParse:
list<string> sentanceParse(string strParse){
list<string> strList;
int len = strParse.length();
int pos = 0;
int count = 0;
for(int i = 0; i < len; i++){
if(strParse.at(i) == '.' || strParse.at(i) == '!' || strParse.at(i) == '?'){
if(i < strParse.length() - 1){
while(i < strParse.length() - 1 && (strParse.at(i+1) == '.' || strParse.at(i+1) == '!' || strParse.at(i+1) == '?')){
if(strParse.at(i+1) == '?'){
strParse.replace(i, 1, "?");
}
strParse.erase(i+1, 1);
len -= 1;
}
}
char strTemp[2000];
int lenTemp = strParse.copy(strTemp, i - pos + 1, pos);
strTemp[lenTemp] = '\0';
std::string strAdd(strTemp);
strList.push_back(strAdd);
pos = i + 1;
count ++;
}
}
if(count == 0){
strList.push_back(strParse);
}
return strList;
}
Your implementation of sentence parse is wrong, here is a simpler correct solution.
std::list<std::string> sentence_parse(const std::string &str){
std::string temp;
std::list<std::string> t;
for(int x=0; x<str.size();++x){
if(str[x]=='.'||str[x]=='!'||str[x]=='?'){
if(temp!="")t.push_back(temp);//Handle special case of input with
//multiple punctuation Ex. Hi!!!!
temp="";
}else temp+=str[x];
}
return t;
}
EDIT:
Here is a full example program using this function. Type some sentences in your console, press enter and it will spit the sentences out with a newline separating them instead of punctuation.
#include <iostream>
#include <string>
#include <list>
std::list<std::string> sentence_parse(const std::string &str){
std::string temp;
std::list<std::string> t;
for(int x=0; x<str.size();++x){
if(str[x]=='.'||str[x]=='!'||str[x]=='?'){
if(temp!="")t.push_back(temp);//Handle special case of input with
//multiple punctuation Ex. Hi!!!!
temp="";
}else temp+=str[x];
}
return t;
}
int main (int argc, const char * argv[])
{
std::string s;
while (std::getline(std::cin,s)) {
std::list<std::string> t= sentence_parse(s);
std::list<std::string>::iterator x=t.begin();
while (x!=t.end()) {
std::cout<<*x<<"\n";
++x;
}
}
return 0;
}
// This function should be easy to adapt to any basic libary
// this is in Windows MFC
// pass in a string, a char and a stringarray
// returns an array of strings using char as the separator
void tokenizeString(CString theString, TCHAR theToken, CStringArray *theParameters)
{
CString temp = "";
int i = 0;
for(i = 0; i < theString.GetLength(); i++ )
{
if (theString.GetAt(i) != theToken)
{
temp += theString.GetAt(i);
}
else
{
theParameters->Add(temp);
temp = "";
}
if(i == theString.GetLength()-1)
theParameters->Add(temp);
}
}