Getting Started

(lily) #1

Chapter 8: C Pointers and Arrays


d this out for you by
ending them some money at: http://www.sourceforge.net/donate.

erminates if the byte is '\0' or if i = 60.
is 'null' and terminates C strings
s too much overrun if we get a bad pointer
the string size
byte(&pFlashStr[i]) && i < 60; i++)
sendChar(pgm_read_byte(&pFlashStr[i]));

stant character pointer as an argument. We can send a

amed array. (Aren’t you glad I didn’t say
ponymous array’?).

he first time I saw an array of pointers to arrays I thought somebody was either
to obfuscate the code for job security. But I’ve learned
ful programming technique.

flash ROM, but this is not C and needs to be wrapped with some code to make its
use C-like, which is what the PROGMEM does. The details get more complex
than we want right now so just thank the guys who figure
s


We send this string to the PC by defining a sendFString function:


// Send a string located in Flash ROM
void sendFString(const char *pFlashStr)
{
uint8_t i;


// The 'for' logic t
// '\0'
// The 60 prevent
// and it limits
for (i = 0; pgmread
{


}
}


The function takes a con
string as follows:


sendFString(&ERROR_YOUFOOBARED[0]);


which explicitly shows that we are sending the address of the first element in the
array. Or we could use the simpler:


sendFString(ERROR_YOUFOOBARED);

which is exactly the same thing since the ERROR_YOUFOOBARED is a
constant character pointer to the so-n
‘e


Using an array of pointers to arrays.


T
putting me on or trying
that, complex as it sounds, it’s actually a use

Free download pdf