0

Hi guys, I'm pretty much a C newbie, but I've dabbled in other languages over the years. For my current project I'm using mikroElektronica Pro C on a PIC microcontroller.

I've got a 2-dimensional array defined like this:

const char FONTTABLE[96][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} 
};

I want to select a given row from this using the index (0-95), then pass that element (a 5 element array) to a routine that will process each byte for the size of the row (5 in this case). I'm pretty sure I need to use a pointer, but no matter what I do I get compile errors.

Any tips?

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by gerard4143
0

Hi guys, I'm pretty much a C newbie, but I've dabbled in other languages over the years. For my current project I'm using mikroElektronica Pro C on a PIC microcontroller.

I've got a 2-dimensional array defined like this:

const char FONTTABLE[96][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} 
};

I want to select a given row from this using the index (0-95), then pass that element (a 5 element array) to a routine that will process each byte for the size of the row (5 in this case). I'm pretty sure I need to use a pointer, but no matter what I do I get compile errors.

Any tips?

Try something like below...Note I truncated your array

#include <stdio.h>
#include <stdlib.h>

const char FONTTABLE[6][5]= 
{ 
{0x00,0x00,0x00,0x00,0x00}, 
{0x00,0x00,0x5f,0x00,0x00}, 
{0x00,0x07,0x00,0x07,0x00}, 
{0x00,0x41,0x36,0x08,0x00}, 
{0x10,0x08,0x08,0x10,0x08}, 
{0x78,0x46,0x41,0x46,0x78} 
};

int main(int argc, char**argv)
{
	int i = 0, j = 0;

	for (i = 0; i < 6; ++i)
	{
		fprintf(stdout, "row[%d]\n", i);
		for (j = 0; j < 5; ++j)
		{
			fprintf(stdout, " 0x%x", FONTTABLE[i][j]);
		}
		fputs("\n", stdout);
	}
	exit(EXIT_SUCCESS);
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.