This is wierd.

This is a discussion on This is wierd. within the C++ Programming forums, part of the General Programming Boards category; When I run this program, it displays correctly, but it also creates a bunch of wierd ascii symbols(smilie face, etc...). ...

  1. #1
    Registered User Ranedhel's Avatar
    Join Date
    Jun 2003
    Posts
    34

    Unhappy This is wierd.

    When I run this program, it displays correctly, but it also creates a bunch of wierd ascii symbols(smilie face, etc...).

    Code:
    char map[9][9];
    {
    map[0][0] = '.';
    map[1][0] = '.';
    map[2][0] = '.';
    map[3][0] = '.';
    map[4][0] = '.';
    map[5][0] = '.';
    map[6][0] = '.';
    map[7][0] = '.';
    map[8][0] = '.';
    map[9][0] = '.';
    map[1][1] = '.';
    map[2][1] = '.';
    map[3][1] = '.';
    map[4][1] = '.';
    map[5][1] = '.';
    map[6][1] = '.';
    map[7][1] = '.';
    map[8][1] = '.';
    map[9][1] = '.';
    map[1][2] = '.';
    map[2][2] = '.';
    map[3][2] = '.';
    map[4][2] = '.';
    map[5][2] = '.';
    map[6][2] = '.';
    map[7][2] = '.';
    map[8][2] = '.';
    map[9][2] = '.';
    map[1][3] = '.';
    map[2][3] = '.';
    map[3][3] = '.';
    map[4][3] = '.';
    map[5][3] = '.';
    map[6][3] = '.';
    map[7][3] = '.';
    map[8][3] = '.';
    map[9][3] = '.';
    map[1][4] = '.';
    map[2][4] = '.';
    map[3][4] = '.';
    map[4][4] = '.';
    map[5][4] = '.';
    map[6][4] = '.';
    map[7][4] = '.';
    map[8][4] = '.';
    map[9][4] = '.';
    map[1][5] = '.';
    map[2][5] = '.';
    map[3][5] = '.';
    map[4][5] = '.';
    map[5][5] = '.';
    map[6][5] = '.';
    map[7][5] = '.';
    map[8][5] = '.';
    map[9][5] = '.';
    map[1][6] = '.';
    map[2][6] = '.';
    map[3][6] = '.';
    map[4][6] = '.';
    map[5][6] = '.';
    map[6][6] = '.';
    map[7][6] = '.';
    map[8][6] = '.';
    map[9][6] = '.';
    map[1][7] = '.';
    map[2][7] = '.';
    map[3][7] = '.';
    map[4][7] = '.';
    map[5][7] = '.';
    map[6][7] = '.';
    map[7][7] = '.';
    map[8][7] = '.';
    map[9][7] = '.';
    map[1][8] = '.';
    map[2][8] = '.';
    map[3][8] = '.';
    map[4][8] = '.';
    map[5][8] = '.';
    map[6][8] = '.';
    map[7][8] = '.';
    map[8][8] = '.';
    map[9][8] = '.';
    map[1][9] = '.';
    map[2][9] = '.';
    map[3][9] = '.';
    map[4][9] = '.';
    map[5][9] = '.';
    map[6][9] = '.';
    map[7][9] = '.';
    map[8][9] = '.';
    map[9][9] = '.';
    }
    for(mapx = 0; mapx < 10; mapx++)
    {
    cout << map[mapx][mapy] << endl;
    for(mapy = 0; mapy < 10; mapy++)
    {
    cout << map[mapx][mapy];
    }
    }
    -Elven Forge Software-
    (Lead Designer)

    http://www.geocities.com/elvenforge

    **infected by frenchfry164**
    I am a signature virus. Please add me to your signature so that I may multiply

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >char map[9][9];

    Your map is 10x10:
    char map[10][10];

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    first of all map[9][0] = '.'; is wrong. You can't index into the 10th element in the array. It's only 9 big.

    Second... the word is spelled W-E-I-R-D
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    Registered User Ranedhel's Avatar
    Join Date
    Jun 2003
    Posts
    34

    Red face Re:

    I should have known(on both counts)
    -Elven Forge Software-
    (Lead Designer)

    http://www.geocities.com/elvenforge

    **infected by frenchfry164**
    I am a signature virus. Please add me to your signature so that I may multiply

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    It would be a really good idea to initialize your matrix with a loop instead of a long string of assignment statements.
    My best code is written with the delete key.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Or just to give you some other ideas:
    Code:
    char map[10][10] = {
    '.','.','.','.','.','.','.','.','.','.',
    '.','.','.','.','.','.','.','.','.','.',
    '.','.','.','.','.','.','.','.','.','.',
    '.','.','.','.','.','.','.','.','.','.',
    '.','.','.','.','.','.','.','.','.','.',
    '.','.','.','.','.','.','.','.','.','.',
    '.','.','.','.','.','.','.','.','.','.',
    '.','.','.','.','.','.','.','.','.','.',
    '.','.','.','.','.','.','.','.','.','.',
    '.','.','.','.','.','.','.','.','.','.'};
    Also:
    Code:
    >for(mapx = 0; mapx < 10; mapx++)
    >{
    >cout << map[mapx][mapy] << endl;  //You don't need this line.  mapy isn't initialized yet.
    >for(mapy = 0; mapy < 10; mapy++)
    >{
    >cout << map[mapx][mapy];
    >}
    >}

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,607
    You could skin that cat this way too.
    Code:
        char map[10][10];
        memset(map, '.', sizeof(map));
    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wierd struct error
    By sujeet1 in forum C Programming
    Replies: 5
    Last Post: 09-27-2007, 06:38 AM
  2. OpenGL Wierd **** - Order of Drawing Stuff?
    By Tonto in forum Game Programming
    Replies: 9
    Last Post: 11-09-2006, 08:56 PM
  3. Wierd chars...
    By mikahell in forum C++ Programming
    Replies: 8
    Last Post: 08-06-2006, 07:18 PM
  4. make user press enter / wierd code thingy
    By CorvusVita in forum C++ Programming
    Replies: 10
    Last Post: 04-05-2006, 09:55 AM
  5. Compiler Is Wierd
    By gnu-ehacks in forum C++ Programming
    Replies: 4
    Last Post: 12-06-2001, 03:43 AM

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