Thread: 2-dimensional arrays

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    30

    2-dimensional arrays

    I was wondering how you put blank spaces in 2-dimensional arrays.
    Thanks

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    err...

    you mean,

    Code:
    char arr[2][2] = { {' ', ' '}, {' ', ' '} };
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    30
    oh ok thanks, I wasn't putting the dashes in because I thought that was only for outputting.
    Thanks heaps!!

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    30
    I just did that but the compiler is saying parse error. I also tried with " " but that doesn't work either.
    Any idea why?

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Well, that array definition is correct. Copy/paste the bit of your code that is producing the error, please...
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    30
    Code:
    int bankcheque [27][3] = {{" "," "," "," ",_," "," ",_," "," "," "," "," ",_," "," ",_," "," ",_," "," ",_," "," ",_," "," ",_," "},
                                   {" "," ",|," ",_,|," ",_,|,|,_,|,|,_," ",|,_," "," "," ",|,|,_,|,|,_,|,|," ",|},
                                   {" "," ",|,|,_," "," ",_,|," "," ",|," ",_,|,|,_,|," "," ",|,|,_,|," ",_,|,|,_,|} };

    Sorry, i know it's long but this is it with the " ".

  7. #7
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Wow...

    1st. You are declaring your array as int, but feeding it with strings. It's either an array of strings, or an array of ints.

    2nd. The compiler doesn't know what the underscores and the pipe characters you have there mean.

    3rd. You are defining an array larger that what you declared.

    4th. You are missing the ending } and ;

    I'm not sure what you want... but maybe you want this:

    Code:
       char bankcheque[3][30] = 
       {
         {' ',' ',' ',' ','_',' ',' ','_',' ',' ',' ',' ',' ','_',' ',' ','_',' ',' ','_',' ',' ','_',' ',' ','_',' ',' ','_',' '},
         {' ',' ','|',' ','_','|',' ','_','|','|','_','|','|','_',' ','|','_',' ',' ',' ','|','|','_','|','|','_','|','|',' ','|'},
         {' ',' ','|','|','_',' ',' ','_','|',' ',' ','|',' ','_','|','|','_','|',' ',' ','|','|','_','|',' ','_','|','|','_','|'}
       };
    You need to learn about variable declaration and types. A pair of " (double quotes) is used for delimiting literal strings. A pair of ' (single quotes) is used for delimiting literal chars.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    30
    Thankyou soooooo much. Working now. Your help is much apprecaited!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointers and multi dimensional arrays
    By andrea72 in forum C++ Programming
    Replies: 5
    Last Post: 01-23-2007, 04:49 PM
  2. Dynamic two dimensional arrays
    By ThWolf in forum C++ Programming
    Replies: 14
    Last Post: 08-30-2006, 02:28 PM
  3. Two dimensional arrays
    By Masschino in forum C Programming
    Replies: 9
    Last Post: 05-18-2004, 08:17 PM
  4. two dimensional arrays
    By ssjnamek in forum C++ Programming
    Replies: 4
    Last Post: 05-01-2002, 08:12 PM
  5. Two dimensional arrays
    By Jax in forum C Programming
    Replies: 1
    Last Post: 11-07-2001, 12:53 PM