Thread: 2 dimensional char array question

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    Question 2 dimensional char array question

    I'm in doubt about referencing a two dimensional array, which one is right?
    Code:
    char 40charName[41];
    char test[20][41];// An array containing 20 names, upt to 40 characters
    for(int i=0;i<20;i++)
      strcpy(test[i], 40charName);
    Is this correct, or should the array decl. be:
    Code:
    char test[41][20];
    Any clues??

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    your comment is correct in first example.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    That's what i thought.
    I just had to check, my program halts, so i have to see if any memory is overwritten...

  4. #4
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Did you think about declaring an array of strings( char * or using the string class ), maybe it will do the job for you instead a two dimentional char array.
    none...

  5. #5
    noob
    Guest
    char 40charName[41]; <-- cannot init var with number in front of it's name

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multi dimensional array
    By $l4xklynx in forum C Programming
    Replies: 7
    Last Post: 01-03-2009, 03:56 AM
  2. comparing fields in a text file
    By darfader in forum C Programming
    Replies: 9
    Last Post: 08-22-2003, 08:21 AM
  3. Replies: 5
    Last Post: 05-30-2003, 12:46 AM
  4. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM