lundi 23 mars 2015

Collecting String Elements from an array and grouping them together into another string array?


I have an array which consists of a group of string elements. I want to collect a group of elements, as shown in my code below, and place group of these elements in a new element of another array.


Consider the array I want to collect values from is something like ".", "-", ".",


The program I am writing decodes Morse code, not that it matters, it just means that the array will have recurring values in random orders:



for (int n = 0; n < 100; n++)
{
if ((didah[n] == ".") || (didah[n] == "-"))
{
currentDidah = n;
//cout <<"first didah" <<currentDidah<<endl;
}
if ((didah[n]== "." || (didah[n]=="-") && (didah[n+1] == " ") && (didah[n+2] == " " )) )
{
lastDidah = n;
//cout <<"last didah" <<lastDidah;
}
while ((n>=currentDidah) && (n<lastDidah))
{// most likely infinite
valInBet += didah[n];
cout << valInBet << "WORKING"<< endl;
collection[n] = valInBet;
}


I have determined when to collect the values and when to stop. The main problem I know is the while loop, the logic behind it is not correct because last didah is always bigger than "n" (for loop counter).


All help appreciated, thanks in advance :)




Aucun commentaire:

Enregistrer un commentaire