View unanswered posts | View active topics It is currently Sun Oct 26, 2014 3:54 am






Reply to topic  [ 7 posts ] 
Array giving wrong results? 
Author Message
Rookie

Joined: Mon Aug 20, 2007 4:01 am
Posts: 28
Post Array giving wrong results?
Hello
I am creating a baudot machine, and am having problems with an array. What I'm doing is inputting a code '00011' then using a for next loop to go through baudotCode to get an index number to get the relevant letter from baudotLTRS.

The code below displays:

00011
L 3
A

What its supposed to display is:

00011
A 3
A

Why doesn't it? putting the number directly baudotLTRS[3] displays the character correctly. But the baudotLTRS[i] returns the letter L. But it selects the right number, 3. I'm using the latest version 1.40.

Can anyone help?

Karl.

Code:
string baudotCode[] = {"00000","00001","00010","00011","00100","00101","00110","00111","01000","01001","01010","01011","01100","01101","01110","01111","10000","10001","10010","10011","10100","10101","10110","10111","11000","11001","11010","11011","11100","11101","11110","11111"};
string baudotLTRS[] = {"NULL","E","LF","A","SP","S","I","U","CR","D","R","J","N","F","C","K","T","Z","L","W","H","Y","P","Q","O","B","G","FIGS","M","X","V","LRTS"};

//this cut down test data works:
//string baudotCode[8] = {"00000","00001","00010","00011","00100","00101","00110","00111"};
//string baudotLTRS[8] = {"NULL","E","LF","A","SP","S","I","U"};

void decodeInput(string typedLetter, string &outChar) {
  int baudotCount = sizeof(baudotCode);
  for(int i = 0; i < baudotCount; i++) {
    if (typedLetter == baudotCode[i]) { outChar = baudotLTRS[i] + " " + i; break; }
    }
}

task main() {
  string typedLetter="00011";  // the letter A
  string outChar;
  decodeInput(typedLetter,outChar);

  nxtDisplayCenteredBigTextLine(1, typedLetter);
  nxtDisplayCenteredBigTextLine(3, outChar);
  nxtDisplayCenteredBigTextLine(5, baudotLTRS[3]);
  while (true) {}
}


Tue Aug 19, 2008 8:23 pm
Profile
Rookie
User avatar

Joined: Thu Jun 26, 2008 11:27 am
Posts: 21
Location: Johannesburg, South Africa
Post Re: Array giving wrong results?
Hi

I have also noticed odd results with string arrays.
Try this for really strange (assuming it does the same on your brick as it does on mine)
Code:
string array1[] = {"1","2","3","4","5","6","7","8","9","10","11","12"};
string array2[] = {"Now","is","the","time","for","all","good","men"};

task main()
{
  for(int i = 0; i < 8; i++)
  {
    nxtDisplayTextLine(i, array2[i]);
  };
  while (true) {}
}
This works just fine and I get
Now
is
the
time
for
all
good
men

If I change the code so there is a 13th element in array1 thus:
Code:
string array1[] = {"1","2","3","4","5","6","7","8","9","10","11","12","13"};
string array2[] = {"Now","is","the","time","for","all","good","men"};

task main()
{
  for(int i = 0; i < 8; i++)
  {
    nxtDisplayTextLine(i, array2[i]);
  };
  while (true) {}
}

Now I get:
Now
ow
w

Go figure!


Wed Aug 20, 2008 3:56 am
Profile WWW
Rookie

Joined: Mon Aug 20, 2007 4:01 am
Posts: 28
Post Re: Array giving wrong results?
Abbeyjean wrote:
Now I get:
Now
ow
w

Go figure!


Yes, with your example I get the same results too. Further experiments with the baudotCode and baudotLTRS arrays, their size looks to be limited to ten elements.

Karl.


Wed Aug 20, 2008 4:10 am
Profile
Rookie

Joined: Mon Aug 20, 2007 4:01 am
Posts: 28
Post Re: Array giving wrong results?
Hello,
experimenting with the original example, I changed the first element of baudotLTRS from NULL to ABCDEFG.

Using 00011 (3) displays DEFG
Using 00101 (5) displays FG

So instead of reading the element, its turned into some sort of weird substring function.

That's not right.

Karl.


Thu Aug 21, 2008 4:24 am
Profile
Rookie

Joined: Mon Aug 20, 2007 4:01 am
Posts: 28
Post Re: Array giving wrong results?
But wait, there's more. I was thinking, as the shorter array works, why not chunk the array. like so:

Code:
string baudotCodeA[] = {"00000","00001","00010","00011","00100","00101"};
string baudotCodeB[] = {"00110","00111","01000","01001","01010","01011"};
string baudotCodeC[] = {"01100","01101","01110","01111","10000","10001"};
string baudotCodeD[] = {"10010","10011","10100","10101","10110","10111"};
string baudotCodeE[] = {"11000","11001","11010","11011","11100","11101"};
string baudotCodeF[] = {"11110","11111"};

string baudotLTRSa[] = {"NULL","E","LF","A","SP","S"};
string baudotLTRSb[] = {"I","U","CR","D","R","J"};
string baudotLTRSc[] = {"N","F","C","K","T","Z"};
string baudotLTRSd[] = {"L","W","H","Y","P","Q"};
string baudotLTRSe[] = {"O","B","G","FIGS","M","X"};
string baudotLTRSf[] = {"V","LRTS"};

void decodeInput(string typedLetter, string &outChar) {
  int baudotCount = sizeof(baudotCodeA);
  for(int i = 0; i < baudotCount; i++) {
    if (typedLetter == baudotCodeA[i]) { outChar = baudotLTRSa[i] + " " + i; break; }
    }
}

task main() {
  string typedLetter="00011";  // the letter A
  string outChar;
  decodeInput(typedLetter,outChar);

  nxtDisplayCenteredBigTextLine(1, typedLetter);
  nxtDisplayCenteredBigTextLine(3, outChar);
  nxtDisplayCenteredBigTextLine(5, baudotLTRSa[3]);
  while (true) {}
}



and did it work? No.

however removing the B-F lines, and it does. But that's not very helpful.

Code:
string baudotCodeA[] = {"00000","00001","00010","00011","00100","00101"};

string baudotLTRSa[] = {"NULL","E","LF","A","SP","S"};

void decodeInput(string typedLetter, string &outChar) {
  int baudotCount = sizeof(baudotCodeA);
  for(int i = 0; i < baudotCount; i++) {
    if (typedLetter == baudotCodeA[i]) { outChar = baudotLTRSa[i] + " " + i; break; }
    }
}

task main() {
  string typedLetter="00011";  // the letter A
  string outChar;
  decodeInput(typedLetter,outChar);

  nxtDisplayCenteredBigTextLine(1, typedLetter);
  nxtDisplayCenteredBigTextLine(3, outChar);
  nxtDisplayCenteredBigTextLine(5, baudotLTRSa[3]);
  while (true) {}
}



Thu Aug 21, 2008 5:13 am
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Array giving wrong results?
hi,
yes, I can copy this. Did you report it to the bug tracker? Seems to be sth. for the de-velo-bugg-ers ;P
BTW/OT: what sort of multiplexer are you using for the 5 baudot input keys?

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Thu Aug 21, 2008 5:34 am
Profile
Rookie

Joined: Mon Aug 20, 2007 4:01 am
Posts: 28
Post Re: Array giving wrong results?
Ford Prefect wrote:
hi,
yes, I can copy this. Did you report it to the bug tracker? Seems to be sth. for the de-velo-bugg-ers ;P
BTW/OT: what sort of multiplexer are you using for the 5 baudot input keys?


I'm not using a multiplexer, I'm using a colour sensor. If I ever get this working, I'll be documenting it, I'll post a link here when complete.

Karl.


Thu Aug 21, 2008 7:08 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.