Initializing multiscripted arrays

This is a discussion on Initializing multiscripted arrays within the C Programming forums, part of the General Programming Boards category; What is the correct form to initialize a multiscripted array? 1- Code: char names[3][11] = {{"texto1.txt"}, {"texto2.txt"}, {"texto3.txt"}}; 2- Code: ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    204

    Initializing multiscripted arrays

    What is the correct form to initialize a multiscripted array?
    1-
    Code:
    char names[3][11] = {{"texto1.txt"}, {"texto2.txt"}, {"texto3.txt"}};
    2-
    Code:
    char names[3][11] = {"texto1.txt", "texto2.txt", "texto3.txt"};
    Thanks.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Both of those forms.
    6.7.8 Initialization

    14 An array of character type may be initialized by a character string literal, optionally enclosed in braces.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Initializing arrays in a class
    By ejohns85 in forum C++ Programming
    Replies: 2
    Last Post: 03-19-2009, 10:06 AM
  2. Replies: 23
    Last Post: 12-06-2008, 01:39 PM
  3. initializing multi-dimensional arrays
    By cyberfish in forum C++ Programming
    Replies: 4
    Last Post: 10-31-2007, 09:15 PM
  4. newbee: initializing arrays
    By breaka in forum C Programming
    Replies: 11
    Last Post: 06-12-2006, 01:20 PM
  5. Initializing dynamic arrays
    By cunnus88 in forum C++ Programming
    Replies: 9
    Last Post: 11-21-2005, 09:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21