Perhaps I should have said, I'm happy about extracting the row, just not sure about getting a handle on it. I think I'm beginning to understand, but I'm not sure about
:
Code:
p+1 = p + sizeof(char)
I think I will need to use sizeOf, because the same routine is going to process char arrays of different sizes - the above is a sample of one of them.
I'm really not sure what your question is. If you can figure out how to extract a row, then extracting characters from the row is basically the same thing.
Code:
#include <stdio.h>
/* If you leave out the last dimension, the compiler will calculate it for you.
*/
static const char FONTTABLE[][5]=
{
{0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x5f,0x00,0x00},
{0x00,0x07,0x00,0x07,0x00},
/** [90 rows snipped] **/
{0x00,0x41,0x36,0x08,0x00},
{0x10,0x08,0x08,0x10,0x08},
{0x78,0x46,0x41,0x46,0x78}
};
void print(const char data[5]) {
int x;
for(x = 0; x < 5; x ++) {
printf("0x%02x ", data[x]);
}
printf("\n");
}
int main(int argc, char *argv[]) {
print(FONTTABLE[2]);
return 0;
}
And by the way: my example might not have used pointers directly, but arrays behave in much the same way most of the time, especially when you pass them as arguments to functions.
I just noticed the last line of your post. If you're dealing with arrays of different sizes, then you can't pass an "array" parameter like char data[5]; you have to pass a pointer to the first element, as well as the number of elements in the array. For example:
Code:
#include <stdio.h>
/* If you leave out the last dimension, the compiler will calculate it for you.
*/
static const char FONTTABLE[][5]=
{
{0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x5f,0x00,0x00},
{0x00,0x07,0x00,0x07,0x00},
/** [90 rows snipped] **/
{0x00,0x41,0x36,0x08,0x00},
{0x10,0x08,0x08,0x10,0x08},
{0x78,0x46,0x41,0x46,0x78}
};
void print(const char *data, size_t size) {
size_t x;
for(x = 0; x < size; x ++) {
printf("0x%02x ", data[x]);
}
printf("\n");
}
int main(int argc, char *argv[]) {
print(FONTTABLE[2], sizeof(FONTTABLE[0])/sizeof(FONTTABLE[0][0]));
return 0;
}
The sizeof() part just gives you 5, in this example.
Maybe you can be a little more specific as to exactly what you're trying to do?