User manual
RP6 ROBOT SYSTEM - 4. Programming the RP6
4.4.9. Arrays, Strings, Pointers...
A great number of further interesting C-features are waiting to be discussed, but for
details we will have to refer to available literature!
Most of the program examples can be understood without further study. In the re-
maining sections of this crash course we describe only a few examples and concepts in
a short overview, which of course is not very detailed.
First of all we will discuss arrays. An array allows you to store a predefined number of
elements of a the same data type. The following sample array may be used to store
10 bytes:
uint8_t myFavouriteArray[10];
In one single line we declared 10 variables of identical data type, which now may be
addressed by an index:
myFavouriteArray[0] = 8;
myFavouriteArray[2] = 234;
myFavouriteArray[9] = 45;
Each of these elements may be treated like a standard variable.
Attention: the index always starts at 0 and declaring an array containing n elements
will result in an index ranging from 0 up to n-1 ! The sample array provides 10 ele-
ments indexed from 0 up to 9.
Arrays are extremely helpful for storing a great number of variables with identical
data type and may easily be manipulated in a loop:
uint8_t i;
for(i = 0; i < 10; i++)
writeInteger(myFavouriteArray[i],DEC);
The previous code snippet will output all array elements (in this case without any sep-
arators of line breaks). A quite similar loop may be used to fill an array with values.
In C, strings are handled with by a very similar concept. Standard strings will be
coded by ASCII characters, requiring one byte for each character. Now C simply
defines strings as arrays, which may be considered as arrays of characters. This
concept allows us to define and store a predefined string "abcdefghijklmno" in
memory:
uint8_t aSetOfCharacters[16] = "abcdefghijklmno";
The previously discussed programming samples already contained a few UART-func-
tions for outputting strings with the serial interface. Basically these strings are arrays.
However, instead of handling a complete array, these functions will only refer to the
first element's address in the array. The variable containing this first element's ad-
dress is named “Pointer”. We may generate a pointer to a given array element by
writing &MyFavouriteArray[x], in which x refers to the indexed element. We may find a
few of these statements in sample programs, e.g.:
uint8_t * PointerToAnElement = &aCharacterString[4];
However at this stage you will not need these concepts to understand most of our
programming samples or to write your own programs.
- 75 -










