#include <iostream>
usingnamespace std;
staticchar* CASplice (char* List, char* Splicers)
{
//Found represents whether a splice was found
bool Found = false;
//Last represents whether the last char was a splice
bool Last = true;
//Pieces represents the number that the Final[][] will initialize the Final[x][]
//It starts at 1 because Final[0] represents the number of strings
int Pieces = 2;
//Represents the number of chars in the string initially given (always has a null)
int CharCount = 1;
//Contains the number of chars in the longest char* that will be made (Will need room for two ints and a null char)
int LongCont = 3;
//Contains the current number of chars needed to create the current char* (always has a null)
int CurCont = 1;
//For loop to iterate through each char in List[]
for (int c=0; List[c]!=0; ++c)
{
//For loop to iterate through each Splicer
for (int s=0; Splicers[s]!=0 && !Found; ++s)
{
//Checks each char for a splice
if (Splicers[s]==List[c])
{
//If Last was a splice then pieces does not increment
if (!Last && List[c + 1]!=0)
{
++Pieces;
cout << " new piece" << Splicers[s] << List[c] << Pieces << "\n";
}
else
{
cout << "no new piece" << Splicers[s] << List[c] << Pieces << "\n";
}
Found = true;
}
}
//If char is not a splice then...
// 1. increase the char count by one
// 2. increase the CurCont
if (!Found)
{
++CharCount;
++CurCont;
//If the CurCont is greater than LongCont, set LongCont to CurCont
if(CurCont>LongCont)
{
LongCont=CurCont;
}
}
else
{
CurCont = 1;
}
//Set Last to the value of found
Last = Found;
//Reset default value of Found
Found = false;
}
//Create Char* to hold all values (It will act as a char**)
cout << Pieces * LongCont << " " << Pieces << " " << LongCont << "\n";
char Final[Pieces * LongCont];
//Set first value to hold the number of strings
Final[0] = Pieces;
//Set second value to hold the number of chars held in each string
Final[1] = LongCont;
//Give null value to end of the string
Final[2] = '\0';
//Set all values to null
for (int i = 3;i <= Final[0]*Final[1]; ++i)
{
Final[i] = '\0';
}
//s holds the current string line
int l=1;
//p holds the current char position
int p=0;
//reset Found
Found = false;
//reset Last
Last = true;
//For loop to iterate through each char in List
for (int c = 0;List[c]!=0;++c)
{
//For loop to iterate through each char in Splicers
for (int s = 0;Splicers[s]!=0&&!Found;++s)
{
//If splicer equals char then set found to true
if (List[c]==Splicers[s])
{
Found = true;
}
}
//If found and the last char was not a splice
if (Found && !Last)
{
//Increment l by one to move to the next array indice
++l;
//Set position to 0
p = 0;
//this is so you can see the output nicer...
cout << "\n";
}
//If not found
elseif (!Found)
{
//Set final[l][p] = List[c]
Final[(Final[1]*l) + p] = List[c];
//this is so you can see the output nicer...
cout << List[c] << " Sent to position" << Final[1]*l + p << "\n";
//This increments the position by one
++p;
}
//Set last to represent whether the last char was splice
Last = Found;
//Reset Found
Found = false;
}
//Also just so that you can see that it came out properly...
for (int i; i<Final[0]*Final[1];++i)
{
cout << Final[i] << " " << i << "\n";
}
//Also just to exemplify that it works...
for (l = 0; l < Final[0]; ++l)
{
for (p = 0; Final[l*Final[1]+p]!=0; ++p)
{
cout << Final[l*Final[1]+p];
}
cout << ".\n";
}
cout << "\n";
//Returns final
return Final;
}
int main()
{
char* n = CASplice("phrase % TOTEST#*m.b,","* ,.!?/");
for (int i = 0; i <142; ++i)
{
cout << n[i] << " " << i << "\n";
}
cin.get();
}