|
Page 1 of 1
|
[ 7 posts ] |
|
Array giving wrong results?
| Author |
Message |
|
karl101
Rookie
Joined: Mon Aug 20, 2007 4:01 am Posts: 28
|
 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 |
|
 |
|
Abbeyjean
Rookie
Joined: Thu Jun 26, 2008 11:27 am Posts: 21 Location: Johannesburg, South Africa
|
 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 |
|
 |
|
karl101
Rookie
Joined: Mon Aug 20, 2007 4:01 am Posts: 28
|
 Re: Array giving wrong results?
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 |
|
 |
|
karl101
Rookie
Joined: Mon Aug 20, 2007 4:01 am Posts: 28
|
 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 |
|
 |
|
karl101
Rookie
Joined: Mon Aug 20, 2007 4:01 am Posts: 28
|
 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 |
|
 |
|
Ford Prefect
Senior Roboticist
Joined: Sat Mar 01, 2008 12:52 pm Posts: 936 Location: a small planet in the vicinity of Beteigeuze
|
 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?
_________________ Ford Prefect
Never purchase release 1.x ! (ancient programmer's wisdom) "Don't argue with idiots. They'll drag you down to their level and then beat you with experience."
|
| Thu Aug 21, 2008 5:34 am |
|
 |
|
karl101
Rookie
Joined: Mon Aug 20, 2007 4:01 am Posts: 28
|
 Re: Array giving wrong results?
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 |
|
|
|
Page 1 of 1
|
[ 7 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 4 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
|
|