Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
/*
Simple 256 x 3 array with data of type string containing reps of numerical
Trying to write to console converted value but filter only one of the inner loop's cycles. 
Why can't the use of "if(rs = 0)" do the filtering?
*/
using namespace System;
using namespace System::IO;
using namespace System::Text;
/* array of 256 x 3 */
void PrintValues(Array^ myArr);
int main()
{
  array<String^, 2>^testArray = gcnew array<String^,2>(256,3);
  /* zero (as string) array ... */
  for (int aa=testArray->GetLowerBound(0);aa<=testArray->GetUpperBound(0);aa++)
    for (int ab=testArray->GetLowerBound(1);ab<=testArray->GetUpperBound(1);ab++)
    {
      testArray->SetValue("0",aa,ab);
    }

 /* comment this next three lines to avoid the print out of the array content */
  PrintValues(testArray);
  Console::WriteLine(" ");
  Console::WriteLine(" ");
  /* add some string content to the zeroed table */
  testArray->SetValue("555",23,1);
  testArray->SetValue("129",128,2);
  testArray->SetValue("141",45,0);
  /* output the tabular data in an admittedly odd fashion (wait ... there's a point here) */
  for (int aa=testArray->GetLowerBound(0);aa<=testArray->GetUpperBound(0);aa++)
    for (int ab=testArray->GetLowerBound(1);ab<=testArray->GetUpperBound(1);ab++)
    {
      if (Convert::ToInt32(testArray[aa,0])>0)
      /* this will return three runs at that value located @ testArray[45,0] all of which are 141 */
        Console::WriteLine("using GetValue: {0}", testArray->GetValue(aa,0));
    }

    //PrintValues(testArray);
    /* Now, here's the "filter" I'd like to add to this for loop; the reason for this question -> seems like a no brainer in an "if-then-else sense". But no! */
    //for (int aa=testArray->GetLowerBound(0);aa<=testArray->GetUpperBound(0);aa++)
    //	for (int ab=testArray->GetLowerBound(1);ab<=testArray->GetUpperBound(1);ab++)
    //	{
    //    if (Convert::ToInt32(testArray[aa,0])>0)
    //    /* this will never return ...  */
    //      if(ab=0)
    //      {
    //       Console::WriteLine("using GetValue: {0}", testArray->GetValue(aa,0));
    //      }
    //  }
}

void PrintValues( Array^ myArr )
{
  System::Collections::IEnumerator^ myEnumerator = myArr->GetEnumerator();
  int i = 0;
  int cols = myArr->GetLength( myArr->Rank - 1 );
  while ( myEnumerator->MoveNext() )
  {
    if ( i < cols )
    {
      i++;
    }
    else
    {
      Console::WriteLine();
      i = 1;
    }
    Console::Write(  "\t{0}", myEnumerator->Current );
  }
}
Posted
Updated 14-Mar-12 10:44am
v3
Comments
OriginalGriff 14-Mar-12 15:59pm    
The code block markers are visible, rather than acting to format the code - I have reported it in Sugs&Bugs.
It's not something you have done wrong - it's a bug by the looks of things!
Nelek 14-Mar-12 16:30pm    
Edition: Pre Tags added (it did work for me, choosing a language not the basic pre's) and changed tabulations a bit to avoid many instructions being "multilined"

1 solution

RedDK wrote:
if(ab=0)

Ahem...[^].
 
Share this answer
 
Comments
[no name] 14-Mar-12 17:56pm    
Beware of the darkside. Stopped they must be; on this all depends. Yoda conditions I recommend.
CPallini 14-Mar-12 18:51pm    
There is no dark side [...], really. As a matter of fact it's all dark.
Sergey Alexandrovich Kryukov 14-Mar-12 19:35pm    
So funny you guys are. And I like the text of the anchor: "Ahem..." -- just right thing to say. 5 for the answer.
--SA
CPallini 15-Mar-12 4:14am    
Thank you. :-)
RedDk 14-Mar-12 20:42pm    
Thanks C,

if(ab==0) it is ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900