Thread: String navigation

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    68

    String navigation

    I have an array of strings
    Code:
    char * s_MainMenu[] =
    {
      "MAINT ",
      " AUTO ",
      "MANUAL",
      "FAILS "
    };
    and a struct
    Code:
    typedef struct
    {
        char **WordstoDisplay;
        uint8_t  MenuState;
        uint8_t  MaxStringIndex;
    }g_sDisplay;
    
    g_sDisplay g_DisplayStates;
    I initialize it.
    Code:
    void set_display_state(uint8_t state_val, uint8_t state_maxind, char **words)
    {
        g_DisplayStates.MenuState = state_val;
        g_DisplayStates.MaxStringIndex = state_maxind;
        g_DisplayStates.WordstoDisplay = words;
    }
    
    set_display_state_ext(MAIN_STATE,MAX_MAIN_INDEX, s_MainMenu);
    now as I suppose g_DisplayStates.WordstoDisplay points to s_MainMenu.

    now I browse with buttons and display strings
    Code:
    WriteText((uint8_t *)(*g_DisplayStates.WordstoDisplay + g_uiCounterPush));
    also tried this way
    WriteText((uint8_t *)(g_DisplayStates.WordstoDisplay + g_uiCounterPush));
    But I see gibberish. Obviously my pointers math is wrong.
    What should I fix?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    So what's wrong with
    Code:
    g_DisplayStates.WordstoDisplay[g_uiCounterPush]
    Are you sure your subscript is in bounds?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    68
    Quote Originally Posted by Salem View Post
    So what's wrong with
    Code:
    g_DisplayStates.WordstoDisplay[g_uiCounterPush]
    Are you sure your subscript is in bounds?
    Thank you. My bad.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. menu navigation using c language
    By chandrasekhar in forum C Programming
    Replies: 5
    Last Post: 11-25-2011, 07:28 AM
  2. Continuous Navigation while X for a Robot
    By Creighton in forum C Programming
    Replies: 3
    Last Post: 06-29-2009, 08:38 PM
  3. TabControl Navigation Issue
    By WaterNut in forum C# Programming
    Replies: 0
    Last Post: 02-14-2008, 02:20 PM
  4. Borland C++ Code Navigation
    By Terisia Doebiel in forum Tech Board
    Replies: 1
    Last Post: 07-26-2007, 04:29 AM
  5. XML Navigation
    By Khelder in forum C# Programming
    Replies: 2
    Last Post: 05-26-2004, 03:19 PM

Tags for this Thread