Subject:
|
Re: NXC/NBC release news
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Fri, 30 Mar 2007 17:54:38 GMT
|
Viewed:
|
4552 times
|
| |
| |
In lugnet.robotics, davis_nxt <dmle@doc.ic.ac.uk> wrote:
> I would have expected the string "hello world" to be printed. However, "* *"
> is printed instead.
> It seems that the value assignment operators for sarr's elements did not
> work.
> Am I using the right syntax?
The standard NXT firmware has a bug in the replace opcode which makes it
impossible to use with multi-dimensional arrays (or ragged arrays of arrays). I
have fixed this bug and submitted the code to folks at NI and LEGO for possible
inclusion in the next official firmware update. Hopefully they will include it.
In the meantime you can use my unofficial build of the standard NXT firmware.
It includes this fix. If you install the unofficial firmware image then you
should be able to use the code as you have it written without any problems.
The alternative is to build the contents of the string array using ArrayBuild*
or to write it in an asm block with the arrbuild opcode (which is all the
ArrayBuild* API functions do).
Like this:
#include "NXCDefs.h"
task main() {
string sarr[];
ArrayBuild3(sarr, "hello", "world", "*");
/*
ArrayInit(sarr, "*",3);
string s1 = "hello";
string s2 = "world";
sarr[0]=s1;
sarr[1]=s2;
*/
string ss1 = sarr[0];
string ss2 = sarr[1];
string tmp = StrCat(ss1, ss2);
TextOut(0, LCD_LINE1, tmp);
Wait(3000);
}
John Hansen
|
|
Message has 1 Reply:
Message is in Reply To:
| | Re: NXC/NBC release news
|
| Hi, Sorry for asking a naive question but I have been trying to create and manipulate an array of strings in NXC without much success. Here is the little test program that I use: #include "NXCDefs.h" task main() { string sarr[]; ArrayInit(sarr, (...) (18 years ago, 30-Mar-07, to lugnet.robotics)
|
4 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|