controlling the console?

I'm trying to make the tic tac toe console game from the beginners exorcises article, but i don't know any way to control the console.
is there a way that i can make a very simple text based GUI that will let me highlight the different squares of the game board? and clear/redraw the screen, when i need to to? from what Ive read i shouldn't use any calls to system..

I'm using Code::Blocks as my IDE, and I'm on windows.
any one know what i should do?

i know i could prolly just get around it and ask the user for the coordinates, but i don't like that :<

also id like to have a way of controlling the color of the text as well...
and maybe formating the text that comes out...
Last edited on
Try PDcurses http://pdcurses.sourceforge.net/
from what Ive read i shouldn't use any calls to system..
You can't have graphics without calling the OS
okay i'll look into that, how exactly do i use it?
and what i ment were these types of things i shouldnt use
 
system("PAUSE");

i think i read about a system() call that clears the screan but i read an article that says its evil..
Last edited on
Use cin.get ( ) or something else along those lines instead of system ( "PAUSE" ). System is just overkill for anything, really.
Last edited on
@NGen
i already knew that, and I'm trying to find out about ways of controlling the console, like clearing the screen, and changing the color of things, and the spacing between things.
I'm new to c++ and i have no idea how to use PDcurses, it isn't a built in thing like #include <iostream> i don't think.
Nope, it's not built in. Anyway, to change the spaces, you can use stream manipulators like setprecision() or fixed. For colors/stuff, that can vary by console/OS, so you are basically stuck using a 3rd party library like PDcurses.
N/PDCurses is good though. You'll need to download it; it will come with instructions on where to place it. If it doesn't; I'll tell you anyway:
1. Open CodeBlocks

2. Navigate to Settings -> Compiler and Debugger...

3. Find the "Search Directories" tab; and add the path where you placed the header (".h") files of PDCurses; e.g.
C:\Program Files\CodeBlocks\PDCurses
C:\Program Files\CodeBlocks\PDCurses\win32

4. Find the "Linker Settings" tab. Click "add" In Link Libraries and type the parths to the libraries, e.g.
C:\Program Files\CodeBlocks\PDCurses\win32\panel.a
C:\Program Files\CodeBlocks\PDCurses\win32\pdcurses.a

5. Then try the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <curses.h>

int main() {
    initscr(); /* Initialize the screen */

    printw("Use this function like printf... but with a w.");

    refresh(); /* Because curses stores your window data in a structure; you need to refresh() when you want
                * to see what you've done */

    endwin(); /* Destroy the curses window */

    return 0;
}


6. Read http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
Change <ncurses.h> to <curses.h> and all the example code should compile and work, even under windows.
Last edited on
i downloaded it but it seems to be a DLL file im confused now D:

the file i got in the zip were:
curses.h
panel.h
pdcurses.dll
pdcurses.lib

what do i do with those?
Last edited on
Why should a library confuse you?
The only things you need to work with it are #including its header and linking to it

curses.h is the file you need to include
pdcurses.dll is for dynamic linking
pdcurses.lib is for static linking
Last edited on
So you have pdcurses.dll?
You'll need to #include <curses.h> and then load the DLL; http://www.codeproject.com/KB/DLL/loadingdll.aspx
That's the best I can do, I'm afraid, unless you download and install cygwin and use that...

Edit: This simplifies things; you just have to statically link pdcurses.lib
Otherwise you'd have to dynamically link pdcurses.dll; meaning if you were to distribute anything the DLL would HAVE to go along with it, in the same folder or, AFAIK, the system32 folder.
Last edited on
@bazzy
it confuses me because I'm new to c++, i don't understand the workings of includes and what any of those linking things mean :(

@chrisname
i don't really understand this linking stuff...
and that talks about VC++ I'll try to figure it out in code blocks tho..
thank you for putting up with my questions..
i don't understand the workings of includes and what any of those linking things mean
#include<header> puts the entire contents of the header file in your source file, the header contains the declarations of some symbols present in the library. Linking your program to a library ( as the word 'link' suggest ) makes your program know where the definitions of those library stuff are.
If you link statically, all the contents of the library will be present in your binary file ( which will be heavier but more portable )
If you link statically, you must have the DLL in the computer to run the program. ( The binary file size would be smaller but you have to make sure that the library is installed in the computer )

chrisname already told you what you need to do, replace the names of the files he gave you to those you have the file downloaded:
2. Navigate to Settings -> Compiler and Debugger...

3. Find the "Search Directories" tab; and add the path where you placed the header (".h") files of PDCurses; e.g.
C:\Program Files\CodeBlocks\PDCurses ( directory in which curses.h is installed )
C:\Program Files\CodeBlocks\PDCurses\win32

4. Find the "Linker Settings" tab. Click "add" In Link Libraries and type the parths to the libraries, e.g.
C:\Program Files\CodeBlocks\PDCurses\win32\panel.a ( library files )
C:\Program Files\CodeBlocks\PDCurses\win32\pdcurses.a


The easiest way of installing curses to work with CodeBlocks on Windows is this: http://pdcurses.slashon.com/ - download the library from there -
Where to get and how to install PDCurses
http://www.cplusplus.com/forum/beginner/11546/page1.html#msg54550

Basics of programming with PDCurses
http://www.cplusplus.com/forum/beginner/5796/page1.html#msg25862

The basics of working with multiple source files
http://www.cplusplus.com/forum/unices/2313/page1.html#msg8761

A simple example of a working PDCurses program and how to compile it on Windows with MinGW:
http://www.cplusplus.com/forum/general/497/page1.html#msg1734

Good luck!
I knew Duoas would come to the rescue..,
Topic archived. No new replies allowed.