2-dimensional arrays

This is a discussion on 2-dimensional arrays within the C++ Programming forums, part of the General Programming Boards category; I was wondering how you put blank spaces in 2-dimensional arrays. Thanks...

  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
    Portugal
    Posts
    7,438
    err...

    you mean,

    Code:
    char arr[2][2] = { {' ', ' '}, {' ', ' '} };
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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
    Portugal
    Posts
    7,438
    Well, that array definition is correct. Copy/paste the bit of your code that is producing the error, please...
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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
    Portugal
    Posts
    7,438
    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.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    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, 03: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, 11:53 AM

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