Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8964639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:38:01+00:00 2026-06-15T16:38:01+00:00

i have the following code in a function char MenuOptions[7][200]; strcpy(MenuOptions[0], Create New /

  • 0

i have the following code in a function

char MenuOptions[7][200];
strcpy(MenuOptions[0], "Create New / Modify Existing Customer");
strcpy(MenuOptions[1], "Create New / Modify Existing Product");
strcpy(MenuOptions[2], "List All customers");
strcpy(MenuOptions[3], "List All Products");
strcpy(MenuOptions[4], "Batch Update of New Stock");
strcpy(MenuOptions[5], "Create Customer Order");
strcpy(MenuOptions[6], "View Last Order for Customer");
switch (displayMenu("Main Menu", MenuOptions, 7, TRUE)) {
etc....

and

char displayMenu(char *name, char *options[], int menuLength,
    enBoolean QuitEnabled) {

    int i;
    printf("%s: \n", name);
    for (i = 0; i < menuLength; i++) {
        printf("\t %d %s.\n", (i + 1), options[i]);
    }
    if (QuitEnabled == TRUE)
        printf("\t Q. Quit\n");
etc

once the displayMenu method is entered though, the MenuOptions array seems to be lost from memory. I tried seeing what options[i] is through the expression window in eclipse and it says that it’s “out of bounds” as a value

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:38:03+00:00Added an answer on June 15, 2026 at 4:38 pm

    First and foremost, turn on warning options in your compiler. Your compiler should have warned you there was a type mismatch.

    MenuOptions is an array of seven arrays of 200 char. When displayMenu is called, and MenuOptions is passed as a parameter, MenuOptions is automatically converted from an array to a pointer to the first of the seven arrays of 200 char.

    In displayMenu, the options parameter is declared with char *options[]. This means that options is an array of pointers to char. In function parameters, [] is special; it suggests that an array will be passed for this parameter, but the array is actually passed by the address of its first argument. Thus, this declaration says that options is a pointer to the first of some number of pointers to char.

    So, you are passing a pointer to the first of seven arrays of 200 char, but the function expects to receive a pointer to the first of some number of pointers to char.

    One way to fix this is to change the declaration of options to char (*options)[200]. This says that options is a pointer to (the first of) arrays of 200 char.

    A better way to fix it may be to change MenuOptions:

    static const char *MenuOptions[] =
    {
        "Create New / Modify Existing Customer",
        "Create New / Modify Existing Product",
        "List All customers",
        "List All Products",
        "Batch Update of New Stock",
        "Create Customer Order",
        "View Last Order for Customer",
    };
    

    (You do not need “7” in the brackets because the compiler will count the strings for you.)

    Then you do not need to change the declaration of options, except that I have added const:

    char displayMenu(char *name, const char *options[], int menuLength,
        enBoolean QuitEnabled) {…
    

    Now:

    • MenuOptions is an array of seven pointers to strings (arrays of char). It is passed as a pointer to pointers to strings, and options is a pointer to pointers to strings, so the types match.
    • MenuOptions does not take more space than required. Before, it was defined with 200 characters for each string. Now, each string takes only as much space as it needs (plus a null character at the end and a pointer to the string in the MenuOptions array).
    • const is added to avoid accidentally changing the strings.
    • MenuOptions is declared static, so that it is initialized at compile time, and you do not need to copy strings into it at run time.

    Finally, you can replace the “7” in the call to displayMenu with sizeof MenuOptions / sizeof *MenuOptions. This divides the size of the array by the size of an element of the array, giving the number of elements in the array. This is preferred over hard-coding a constant because it eliminates the possibility that somebody might change the size of the array without changing the hard-coded constant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following UDF. CREATE FUNCTION [dbo].[udf_GenerateVarcharTableFromStringList] (@list varchar(MAX), @delimiter char(1) = N',')
I have following code: class B{ protected: X *x; public: function(char *data){ // access
I have the following function int namecomp(char c); Part of the function code else
I have following code snippet: self.xmlHttpReq = new XMLHttpRequest(); self.xmlHttpReq.onreadystatechange = function() { if(self.xmlHttpReq.readyState
I have the following code: function isValidAuthor($authorID){ $query = SELECT * FROM jos_users WHERE
I have the following code: function build_all_combinations(input_array){ array = [1,2,3] limit = array.length -
I have the following code: function Person(){ this.age = 30; } function Stats(){ this.age
I have the following code function generate_pdf() { $fdf_data_strings = $this->get_hash_for_pdf(); #$fdf_data_names = array('49a'
I have the following code: function toggleChecked(status) { $(.checkbox).each( function() { $(this).attr(checked,status); }) }
I have the following code: function show(){ var a=document.getElementById('somediv').style.display; a=block; } The above code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.