array-issues

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
merijn0301
Posts: 8
Joined: 27 Jun 2012, 13:43

array-issues

Post by merijn0301 »

]Hi,
I am writing some code to work arrays. It shouldn't be too hard, still I run into some problems.

If I try to assign a value like this..

arrTest[1] = "Greetings"

... the value is not assigned.

I tried to use "ArrayReplace()" but I get an errormessage because this function does nog exist althoug the website (brixcc) does show an explain it.

So : How do I assign a value to an array-element?

Merijn
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: array-issues

Post by mattallen37 »

What type is the variable "arrTest" (how did you declare it)?

Typically I only use arrays to hold numbers, not text. I use each element to contain one number.

Each text character is equivalent to an 8-bit number (typically represented by it's ASCII number), so a string is actually an array of 8-bit numbers (NULL terminated).

NXC does support multi-dim arrays, including of type "string", so it should be possible to do what you want. It all depends on how you declared the array (or re-initialized it).
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: array-issues

Post by afanofosc »

If you don't have ArrayReplace then you probably have an old compiler. Are you running on Windows with BricxCC or on Linux or Mac OS X? If you are running on Windows have you updated to the latest test release from http://bricxcc.sourceforge.net/test_releases/?

More importantly, you probably are not using the enhanced NBC/NXC firmware which is required if you want to be able to use arrays with more than one dimension. A string array is actually a two dimensional byte array. The standard LEGO firmware only supports arrays with one dimension - at least with respect to the REPLACE opcode which is what gets used when you try to change the value of an item in an array.

In any case, if you are using the enhanced NBC/NXC firmware then you will be able to use multi-dimensional arrays, including arrays of strings.

It is also possible that your code is having trouble due to some quirks with how NXC handles array declarations/initialization but that usually leads to runtime aborts rather than simply a value in an array not being replaced like it should have been.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
merijn0301
Posts: 8
Joined: 27 Jun 2012, 13:43

Re: array-issues

Post by merijn0301 »

Hi,

I installed the Nxc/NBC firmware and it work perfrectly.
Indeed I was running the standard 'LEGO"-firmware.

Thank's for the replies
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest