msmithy12
Posts: 94
Joined: Fri Aug 10, 2012 8:57 am

Lookup table (or alternative)

Mon Feb 18, 2013 10:15 am

hi, im planning on using one of my pi's to read a serial input (a test parameter from a serial connected test set) and compare that value to a value stored on the pi. I have multiple types of this equipment and they have individual product codes (the codes are not in an order so can be 001, 025, 148) i am trying to implement a lookup table with all the values and then have the pi look up information in the table and compare it to the serial data.

Code: Select all

static int code[r][c] = {
{001, 60, 24, 13},
{025, 55, 19, 18},
{148, 48, 32, 15},
};

void buttonP_press(GtkWidget *widget, gpointer data)
{
 const char *pin = gtk_entry_get_text(GTK_entry (textbox);
printf("%s\n,code[*pin][2]);
}
basically when i press a button with '025' in the textbox i want '55' printed in the terminal.

but i cant even compile the code.

error 'code' undeclared (so i havent declared my array correctly)

any ideas on how to get my code working, or any ideas on how to implement this differantly (im reasonably new to c)
I assume I know what I`m talking about... I probably don`t

Home: 256mb Made in UK, Rasbmc, 40" Sony Bravia KDL-40v3000
Work: 2b+, Rasbian, 6" Lilliput touchscreen

msmithy12
Posts: 94
Joined: Fri Aug 10, 2012 8:57 am

Re: Lookup table (or alternative)

Mon Feb 18, 2013 10:17 am

i have all the GTK stuff working and declared correctly it was only when i started the lookup table that i got errors!
I assume I know what I`m talking about... I probably don`t

Home: 256mb Made in UK, Rasbmc, 40" Sony Bravia KDL-40v3000
Work: 2b+, Rasbian, 6" Lilliput touchscreen

User avatar
joan
Posts: 15100
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Lookup table (or alternative)

Mon Feb 18, 2013 10:38 am

Try

Code: Select all

static int code[][4] = {
{001, 60, 24, 13},
{025, 55, 19, 18},
{148, 48, 32, 15},
};
iy you plan to add more entries, or

Code: Select all

static int code[3][4] = {
{001, 60, 24, 13},
{025, 55, 19, 18},
{148, 48, 32, 15},
};

Return to “C/C++”