Thread: 3-dim char array

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    351

    3-dim char array

    hi,

    i need to have a table of chars in memory.

    char array[8][241][26];

    each string is 8 chars long. the dimensions of the table is 241 * 26.

    i'm confused about how to assign an entry into the array.

    for example how do i put 0,0 in?

    array[][0][0] = "nnnnnnnn"; or use strcpy

    cheers,

    rotis23

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    >> each string is 8 chars long. the dimensions of the table is 241 * 26.

    Well, which one is for which?

    241 - Tables?
    26 - Rows?
    8 - Chars in each string?

  3. #3
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Here's a declaration for a 3D char array:

    char array[241][26][8];

    which means there'll be :

    1. 8 chars in a string
    2. 26 strings in a table
    3. 241 tables

  4. #4
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    thanks, so that won't mean:

    char array[241][26][8];


    1. 8 chars in a string
    2. 26 COLUMNS
    3. 241 ROWS

    i.e. making a 2-dim table of strings?

    i still need to know how to assign a value using strcpy:

    strcpy(&array[0][0][0], "nnnnnnnn"); ????

    then how do i printf?

    printf("array : %s\n",array[0][0][]); ????

  5. #5
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Just use:
    Code:
    strcpy(array[0][0], "nnnnn");
    And for printing:
    Code:
    printf("array: %s\n", array[0][0]);
    Cheers,
    Monster

  6. #6
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    got it using,

    char array[241][26][8];

    strcpy(&array[0][0][0],"nnnnnnnn");

    printf("array : %s\n",array[0][0]);


    sorry monster, i'll try yours.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  2. code help required
    By Yobbo in forum C Programming
    Replies: 9
    Last Post: 09-02-2005, 11:15 PM
  3. NULL terminating a multi dim char array
    By NickESP in forum C++ Programming
    Replies: 2
    Last Post: 02-05-2003, 03:43 PM
  4. Creating 2D arrays on heap
    By sundeeptuteja in forum C++ Programming
    Replies: 6
    Last Post: 08-16-2002, 11:44 AM
  5. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 11:57 AM