Reading from the console, I get errors and need help

This is a discussion on Reading from the console, I get errors and need help within the C++ Programming forums, part of the General Programming Boards category; I'm trying to read from the console because I writing a chess game for the console and I need to ...

  1. #1
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154

    Question Reading from the console, I get errors and need help

    I'm trying to read from the console because I writing a chess game for the console and I need to figuare out what piece is beign moved, so I need to read from it, but I keep on getting errors when I try this code...
    Code:
    char name[1];
         char Kn[2];
         DWORD Read;
         int x; // original X co-ordinate of the piece being moved.
         int y; // original Y co-ordinate of the piece being moved.
         int a;
         int b;
         
         if(turn == 1)
         {
         turn++; // Sorting out turning system
         }
         else if(turn == 2)
         {
         turn--;
         }
         
         make_move[1] = (int)x; // Finding out what piece has been moved
         make_move[2] = y;
         a = (7*(x - 65)) + 10;
         Position.X = a;
         b = 5*y;
         Position.Y = b;
    
    ReadConsoleOutputCharacter(hOut,
                                   &name,
                                   1,
                                   Position,
                                   Read);
    Thanks in advance...

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >but I keep on getting errors when I try this code...
    What errors?

  3. #3
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Post your errors

  4. #4
    Registered User Finchie_88's Avatar
    Join Date
    Aug 2004
    Posts
    154
    sorry,
    Code:
    Consolechess.cpp:713: error: cannot convert `char (*)[1]' to `CHAR*' for 
       argument `2' to `BOOL ReadConsoleOutputCharacterA(void*, CHAR*, long 
       unsigned int, _COORD, DWORD*)'
    
    make.exe: *** [Consolechess.o] Error 1
    Last edited by Finchie_88; 01-01-2005 at 11:58 AM.


  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,499
    So look at parameter 2 (that's what the error message says)

    My guess is you need to drop the &
    You might also need to declare the array name as a CHAR and not a char

    You could also just drop the [1] from the declaration, since a 1-element array isn't that useful.

  6. #6
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    What exactly is the difference between a CHAR and a char?

    From my extremely limited experience, it seems that when the word is capitalized, it's usually a structure, and when it's lowercase, it's a variable type. Could you please clarify?

  7. #7
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    i think the main difference is that all c++ keywords are in lower-case.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  8. #8
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >What exactly is the difference between a CHAR and a char?
    char is a C++ type and CHAR is a Microsoftism. The idea is that the same code will work under both Unicode and, let's say, ASCII. The only change that would need to be made is defining a macro to say you're using Unicode, and the implementation will supposedly do the right thing:
    Code:
    #ifdef UNICODE
      typedef wchar_t CHAR;
    #else
      typedef char CHAR;
    #endif

  9. #9
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    All right. I think I understand, now. Thanks!

  10. #10
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Quote Originally Posted by RoD
    char is a C++ type and CHAR is a Microsoftism. The idea is that the same code will work under both Unicode and, let's say, ASCII. The only change that would need to be made is defining a macro to say you're using Unicode, and the implementation will supposedly do the right thing:
    Code:
    #ifdef UNICODE
      typedef wchar_t CHAR;
    #else
      typedef char CHAR;
    #endif
    You're thinking of TCHAR, CHAR is always char.
    Quote Originally Posted by MSDN Windows Data Types
    CHAR 8-bit Windows (ANSI) character.
    The C built-in data types are simply typedefed to uppercase for consistency with the WinApi style of all uppercase variable type names.
    Code:
    HANDLE hFile;
    UINT   cWidgets;
    PVOID  pVoid;
    INT    nIndex;   /* INT available for consistency. */
    TCHAR  szFileName[MAX_PATH];
    DWORD  dwWritten;
    Last edited by anonytmouse; 01-01-2005 at 02:36 PM.

  11. #11
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >You're thinking of TCHAR
    Ah, so I am.

  12. #12
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    Okay. So TCHAR is Microsoftism and CHAR is just consistency. Got it.

  13. #13
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >So TCHAR is Microsoftism and CHAR is just consistency.
    Well, they're both Microsoftisms since just about everyone else in the universe refrains from using identifiers with all caps except as macros. Consistency isn't a good reason for changing the language when trying to be consistent with a bad choice to begin with. But, this is the company that chose to deprecate a portion of the standard C library in their latest compiler without the C standard committee's blessing.

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