can you tell me whats wrong(C)

This is a discussion on can you tell me whats wrong(C) within the C Programming forums, part of the General Programming Boards category; Code: #include<stdlib.h> #include<stdio.h> #include<conio.h> main() { printf("Lybyrinth!"); } enum { Left, Right, Up, Down }; bool IsObstacle() { return (WorldArray[21][82] ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    6

    Exclamation can you tell me whats wrong(C)

    Code:
    #include<stdlib.h>
    #include<stdio.h>
    #include<conio.h>
    
    
    main()
    {
    
    
    
    printf("Lybyrinth!");
    }
    enum
    {
       Left,
       Right,
       Up,
       Down
    };
    
    bool IsObstacle()
    {
       return (WorldArray[21][82] != ' ');
    }
    
    void Move(int Direction)
    {
       switch(Direction)
       {
          case Left:
             if(IsObstacle(PlayerX - 1, PlayerY) == false)
             {
                PlayerX--;
             }
             break;
    
          case Right:
             if(IsObstacle(PlayerX + 1, PlayerY) == false)
             {
                PlayerX++;
             }
             break;
    
          case Up:
             if(IsObstacle(PlayerX, PlayerY - 1) == false)
             {
                PlayerY--;
             }
             break;
    
          case Down:
             if(IsObstacle(PlayerX, PlayerY + 1) == false)
             {
                PlayerY++;
             }
             break;
       }
    }
    
    drawmaze()
    {
    clrscr();
    char WorldArray[21][82]=
    
    { 'X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X' },
    { 'X'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' ''X' },
    { 'X'' '' '' ''X''X''X''X''X''X''X''X''X''X''X''X''X'' '' '' ''X''X''X''X''X''X''X''X''X''X''X''X''X'' '' '' ''X'' '' '' ''X''X''X''X''X'' '' '' ''X''X''X''X''X'' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X'' '' '' ''X''X''X''X''X' },
    { 'X'' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' ''X' },
    { 'X''X''X''X''X''X''X''X'' '' '' '' ''X'' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X'' '' '' ''X'' '' '' ''X''X''X''X''X'' '' '' ''X'' '' '' ''X'' '' '' ''X''X''X''X''X'' '' '' ''X''X''X''X''X''X''X''X''X''X''X''X''X'' '' '' ''X' },
    { 'X'' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''X' },
    { 'X'' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X''X''X''X''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X'' '' '' ''X'' '' '' ''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X'' '' '' ''X' },
    { 'X'' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' ''X' },
    { 'X''X''X''X''X'' '' '' ''X'' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X''X''X''X''X''X''X''X''X''X''X''X''X'' '' '' ''X'' '' '' '' ''X''X''X''X' },
    { 'X'' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' ''X' },
    { 'X'' '' '' ''X''X''X''X''X''X''X''X''X''X''X''X''X'' '' '' ''X''X''X''X''X'' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X'' '' '' ''X'' '' '' ''X''X''X''X''X''X''X''X''X''X''X''X''X'' '' '' ''X''X''X''X''X''X''X''X''X''X''X''X''X' },
    { 'X'' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' ''X' },
    { 'X'' '' '' ''X''X''X''X''X'' '' '' ''X'' '' '' ''X''X''X''X''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X''X''X''X''X'' '' '' ''X'' '' '' ''X'' '' '' ''X' },
    { 'X'' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' ''X' },
    { 'X''X''X''X''X'' '' '' ''X'' '' '' ''X'' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X'' '' '' ''X'' '' '' ''X''X''X''X''X''X''X''X''X''X''X''X''X'' '' '' ''X' },
    { 'X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' ''X' },
    { 'X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X'' '' '' ''X'' '' '' ''X'' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X' },
    { 'X'' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' ''X' },
    { 'X'' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X'' '' '' ''X'' '' '' ''X'' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X'' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X'' '' '' '' '' '' '' ''X''X''X''X''X''X''X''X''X'' '' '' ''X' },
    { 'X'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ''X'' '' '' ''X' },
    { 'X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X' };
    }
    Well it's suppose to be a Maze...
    can you point out what to substitute???
    thanks in advance

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    IsObstacle needs rewriting something like...
    Code:
    bool IsObstacle(int x,int y)
    {
       return WorldArray[x][y] != ' ';
    }
    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
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    char WorldArray[21][82]=
    { 'X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X''X

    You need to separate the characters in the array with commas. A smaller example is as follows.
    Code:
    char array[4][8] =
    {
        {'X','X','X','X','X','X','X','X'},
        {'X',' ','X',' ',' ',' ',' ','X'},
        {'X',' ',' ',' ','X','X',' ','X'},
        {'X','X','X','X','X','X','X','X'},
    };
    main()
    Implicit return values are deprecated. Instead use the following and return a value (0, EXIT_FAILURE, or EXIT_SUCCESS).
    int main(void)

    bool IsObstacle()
    This is C++, not C. (Not quite C99 because stdbool.h is not included.[?])
    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

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