We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hopefully this makes sense. I've cut down the actual code to make this short. I have a series of strings as shown:
char code Num1[] = {"One "}; char code Num2[] = {"Two "}; char code Num3[] = {"Three"};
code char code *CHNLTable[] = { Num1, Num2, Num3};
void func(void){ unsigned int *myptr; myptr = &CHNLTable; ...code that uses myptr }
Oh...Just ask... Here's what I came up with.
#include <stdio.h> #include <reg51.h> char code Num1[] = {"One "}; char code Num2[] = {"Two "}; char code Num3[] = {"Three"}; // Num1, 2, and 3 are arrays (in code) of characters (strings). code char code *CHNLTable[] = { Num1, Num2, Num3}; // CHNLTable is an array of pointers (in code) to characters (in code) // So, each element takes 2 bytes (because the pointer is a code pointer) void main (void) { unsigned int *myptr; // myptr is a pointer to an unsigned int (a generic, 3-byte pointer) myptr = &CHNLTable; // I'm not sure what myptr should point to... // the strings or the pointers to the strings... // so, I'm inclined to say this is probably wrong... // It yields this warning: // *** WARNING C182 IN LINE 21 OF MAIN.C: pointer to different objects // Setup the serial port (stolen from HELLO.C) SCON = 0x50; TMOD |= 0x20; TH1 = 221; TR1 = 1; TI = 1; // Here's one of my interpretations of this... { char code *jons_ptr; // jons_ptr is a pointer to a character in code space // so, the sizeof jons_ptr is 2 jons_ptr = CHNLTable[0]; // jons_ptr points to the string "One " printf ("jons_ptr = %s\n", jons_ptr); // This prints it jons_ptr = CHNLTable[1]; // jons_ptr points to the string "Two " printf ("jons_ptr = %s\n", jons_ptr); // This prints it // If you are trying to get a pointer to an individual string... // this is the way to do it... } // Here's another interpretation... { char code * code *jons_dptr; // jons_dptr is a ptr to a ptr (in code space) to a char in code space // I think this is more like what we really want to get! // the sizeof jons_dptr is 2 jons_dptr = CHNLTable; // jons_dptr points to the ptr to the string "One " printf ("*jons_dptr = %s\n", *jons_dptr); // *jons_dptr points to the string "One " jons_dptr++; // Increment jons_dptr so that it points to the ptr to the string "Two " printf ("*jons_dptr = %s\n", *jons_dptr); } while (1); } // Viola!!!