Multi-dimensional array initialization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • masood.iqbal@lycos.com

    Multi-dimensional array initialization

    Hi,

    I have seen at least two ways to initialize multi-dimensional arrays in
    C. One of the ways is shown in a sample code snippet below. The other
    way does not make use of any intermediate braces. In other words, all
    the entries are listed under the same pair of enclosing braces. For
    example:

    char* mdTbl[3][5] = { "One", "Two", "Three", "Four","Fiv e", "Six",
    "Seven",
    "Eight", "Nine", "Ten", "Eleven", "Twelve",
    "Thirteen",
    "Fourteen", "Fifteen" };

    Are the two approaches exactly identical, or is there any difference
    between them?

    Thanks,
    Masood
    /*************** *************** *************** *********
    *************** *************** *************** *********/

    #include <stdio.h>


    char* mdTbl[3][5] = {
    {
    "One",
    "Two",
    "Three",
    "Four",
    "Five"
    },
    {
    "Six",
    "Seven",
    "Eight",
    "Nine",
    "Ten"
    },
    {
    "Eleven",
    "Twelve",
    "Thirteen",
    "Fourteen",
    "Fifteen"
    },
    };


    void
    print_array_ele ment(int row, int column)
    {
    printf("%s\n", mdTbl[row][column]);
    }

    main()
    {
    print_array_ele ment(2, 2);
    }

  • CBFalconer

    #2
    Re: Multi-dimensional array initialization

    masood.iqbal@ly cos.com wrote:[color=blue]
    >
    > I have seen at least two ways to initialize multi-dimensional
    > arrays in C. One of the ways is shown in a sample code snippet
    > below. The other way does not make use of any intermediate braces.
    > In other words, all the entries are listed under the same pair of
    > enclosing braces. For example:[/color]

    Three copies of this malformed posting in less than 100 minutes! I
    suggest you find a newsreader, or a way of using google to make
    readable posts, with indentation and line lengths limited to 72
    (better 65) chars.

    --
    "If you want to post a followup via groups.google.c om, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson


    Comment

    • masood.iqbal@lycos.com

      #3
      Re: Multi-dimensional array initialization

      First of all my apologies for the multiple postings. It was certainly
      not intentional. Actually the google news-server kept giving me an
      error message to the following effect (paraphrasing here):

      Due to a temporary server error the message could not be posted.
      Kindly try again in 30 seconds.

      I actually waited for about a minute or so each time before reposting.
      I kept getting this error, and I kept retrying. It now appears to me
      that those were spurious error messages. I will be more careful in
      future (and just ignore this error message).

      It may a partial consolation that I have already removed the extra
      copies of my postings.

      Comment

      • CBFalconer

        #4
        Re: Multi-dimensional array initialization

        masood.iqbal@ly cos.com wrote:[color=blue]
        >[/color]
        .... snip ...[color=blue]
        >
        > It may a partial consolation that I have already removed the extra
        > copies of my postings.[/color]

        FYI you cannot remove your postings, no matter what your system
        tells you. They are distributed to many thousands of systems
        implementing usenet, most of which do not heed any cancel messages
        (due to misuse by imbeciles). Don't be misled by the idea that
        Google is the medium, it is actually a very small part of it. All
        those extra copies of your original are still residing on my
        system, and on my ISPs system, and many many other places.

        Meanwhile, listen to Eric Sosman.

        --
        "If you want to post a followup via groups.google.c om, don't use
        the broken "Reply" link at the bottom of the article. Click on
        "show options" at the top of the article, then click on the
        "Reply" at the bottom of the article headers." - Keith Thompson


        Comment

        Working...