if this topic is already up pleas point me to it coz i dont even know how to search it....

what i want to do is a small screen in the big screen and have all my printf(""); to print there...
i dont know what else to say so pleas help me and thank you in advance :)

Check out pdcurses.

The other ways to do it would be to use the BIOS console control or the Windows Console API directly.

I don't think TurboVision is available for C...

Im not sure what you gave me =\
and Im not sure u understand what Im trying to do...
I am making a game and I want a small box that will show whats going on in the game all the time...
Im just ok in C. Im not really really good... =\

It is quite likely that I don't understand what you are trying to do. You didn't give me very much information to work on.

What I know is:

  1. you want to use printf(), which is a console I/O function
  2. you want a "small screen" in the "big screen", which can be read two different ways:
    • a subwindow or subregion of your program's main window
    • a separate window on the desktop

    (since you are using console I/O I assumed the first)

  3. and now I know that you are writing a game

So, for further help, I need further information.

  1. What kind of game are you writing? Textual or graphical? If graphical, are you using SDL or OpenGL, or the Win32 API or some other 2D library?
  2. What exactly do you mean by "big screen" and "small screen"?
  3. What kind of information do you want to print to the small screen? Is it diagnostic? Or information the game player needs to see?

1) its a card game so it will B textual and i am useing the library GRAPHICS.H.

2) "big screen" is the main screen. i am not doing the game as a window... it will B full screen... the "small screen" is what i want to do.. it is a small box on the main screen of the game that will have writeing in it... lile "player 1 has thrown the card 4 of ♥.

3)i dont know what diagnostic is but it is information the game player needs to see.

1) I'm a little confused now. The Turbo C graphics.h library is not a textual interface library. Are you using some other, same-named library that is? (If so, please give me a link to it so I can look at how it works and what you can do with it.)

2) Ah, I understand your confusion on "screen". For all intents and purposes, you can say that you have only one "window" with which to work. If you are using the old graphics.h library that I think you are, it is a very easy technical issue to make a sub-region/window. Let me know about the library and I can point you in the right direction.

3) (A diagnostic is information that describes something, typically for debugging and validation purposes.)

Let me know more about graphics.h and I'll be able to give you some useful info.

i might of misunderstood what you meant by textual and diagnostic =\
here is a link to the graphics.h that i am using...
http://62.0.220.111/dvirl/project/GRAPHICS.H

in the game there is no movement of any kind how ever i do use (line(x,y,x,y); and bar(x,y,x,y); and so on) if that helps at all with understanding what game im doing...

I'm getting a 404 for that link. By default, all files under dvirl/ are private, so you may have to change access rights to it.

Directories get 755, files get 644.

A better solution, though, is to give me a link to where you got the graphics.h file, or attach it here. (Because once you open your directories to public access, anyone can read its contents.)

Often a school will give you the ability to keep a home page in a specific subdirectory, like /dvirl/html/ or something, which you can safely chmod 755 (I presume it is a school --I can't read Hebrew [well, not yet, anyway... :) Someday I'll learn...]).

lol ya its a school.
it should work my teacher is dumb and opened it to every1....
maybe the server was down... it does that sometimes...
and he gave me the turboC with all the files i didn't add any....
anyway...i think i attached it im not sure:P

Attachments
/*  graphics.h

    Definitions for Graphics Package.

    Copyright (c) 1987, 1991 by Borland International
    All Rights Reserved.
*/

#if !defined(__GRAPHICS_H)
#define __GRAPHICS_H

#if !defined( __DEFS_H )
#include <_defs.h>
#endif

enum graphics_errors {      /* graphresult error return codes */
    grOk                =   0,
    grNoInitGraph       =  -1,
    grNotDetected       =  -2,
    grFileNotFound      =  -3,
    grInvalidDriver     =  -4,
    grNoLoadMem         =  -5,
    grNoScanMem         =  -6,
    grNoFloodMem        =  -7,
    grFontNotFound      =  -8,
    grNoFontMem         =  -9,
    grInvalidMode       = -10,
    grError             = -11,   /* generic error */
    grIOerror           = -12,
    grInvalidFont       = -13,
    grInvalidFontNum    = -14,
    grInvalidVersion    = -18
};

enum graphics_drivers {     /* define graphics drivers */
    DETECT,         /* requests autodetection */
    CGA, MCGA, EGA, EGA64, EGAMONO, IBM8514,    /* 1 - 6 */
    HERCMONO, ATT400, VGA, PC3270,          /* 7 - 10 */
    CURRENT_DRIVER = -1
};

enum graphics_modes {       /* graphics modes for each driver */
    CGAC0      = 0,  /* 320x200 palette 0; 1 page   */
    CGAC1      = 1,  /* 320x200 palette 1; 1 page   */
    CGAC2      = 2,  /* 320x200 palette 2: 1 page   */
    CGAC3      = 3,  /* 320x200 palette 3; 1 page   */
    CGAHI      = 4,  /* 640x200 1 page          */
    MCGAC0     = 0,  /* 320x200 palette 0; 1 page   */
    MCGAC1     = 1,  /* 320x200 palette 1; 1 page   */
    MCGAC2     = 2,  /* 320x200 palette 2; 1 page   */
    MCGAC3     = 3,  /* 320x200 palette 3; 1 page   */
    MCGAMED    = 4,  /* 640x200 1 page          */
    MCGAHI     = 5,  /* 640x480 1 page          */
    EGALO      = 0,  /* 640x200 16 color 4 pages    */
    EGAHI      = 1,  /* 640x350 16 color 2 pages    */
    EGA64LO    = 0,  /* 640x200 16 color 1 page     */
    EGA64HI    = 1,  /* 640x350 4 color  1 page     */
    EGAMONOHI  = 0,  /* 640x350 64K on card, 1 page - 256K on card, 4 pages */
    HERCMONOHI = 0,  /* 720x348 2 pages         */
    ATT400C0   = 0,  /* 320x200 palette 0; 1 page   */
    ATT400C1   = 1,  /* 320x200 palette 1; 1 page   */
    ATT400C2   = 2,  /* 320x200 palette 2; 1 page   */
    ATT400C3   = 3,  /* 320x200 palette 3; 1 page   */
    ATT400MED  = 4,  /* 640x200 1 page          */
    ATT400HI   = 5,  /* 640x400 1 page          */
    VGALO      = 0,  /* 640x200 16 color 4 pages    */
    VGAMED     = 1,  /* 640x350 16 color 2 pages    */
    VGAHI      = 2,  /* 640x480 16 color 1 page     */
    PC3270HI   = 0,  /* 720x350 1 page          */
    IBM8514LO  = 0,  /* 640x480 256 colors      */
    IBM8514HI  = 1   /*1024x768 256 colors      */
};

/* Colors for setpalette and setallpalette */

#if !defined(__COLORS)
#define __COLORS

enum COLORS {
    BLACK,          /* dark colors */
    BLUE,
    GREEN,
    CYAN,
    RED,
    MAGENTA,
    BROWN,
    LIGHTGRAY,
    DARKGRAY,       /* light colors */
    LIGHTBLUE,
    LIGHTGREEN,
    LIGHTCYAN,
    LIGHTRED,
    LIGHTMAGENTA,
    YELLOW,
    WHITE
};
#endif

enum CGA_COLORS {
    CGA_LIGHTGREEN     = 1,     /* Palette C0 Color Names   */
    CGA_LIGHTRED       = 2,
    CGA_YELLOW         = 3,

    CGA_LIGHTCYAN      = 1,     /* Palette C1 Color Names   */
    CGA_LIGHTMAGENTA   = 2,
    CGA_WHITE          = 3,

    CGA_GREEN          = 1,     /* Palette C2 Color Names   */
    CGA_RED            = 2,
    CGA_BROWN          = 3,

    CGA_CYAN           = 1,     /* Palette C3 Color Names   */
    CGA_MAGENTA        = 2,
    CGA_LIGHTGRAY      = 3
};


enum EGA_COLORS {
    EGA_BLACK        =  0,      /* dark colors */
    EGA_BLUE         =  1,
    EGA_GREEN        =  2,
    EGA_CYAN         =  3,
    EGA_RED          =  4,
    EGA_MAGENTA      =  5,
    EGA_BROWN        =  20,
    EGA_LIGHTGRAY    =  7,
    EGA_DARKGRAY     =  56,     /* light colors */
    EGA_LIGHTBLUE    =  57,
    EGA_LIGHTGREEN   =  58,
    EGA_LIGHTCYAN    =  59,
    EGA_LIGHTRED     =  60,
    EGA_LIGHTMAGENTA =  61,
    EGA_YELLOW       =  62,
    EGA_WHITE        =  63
};

enum line_styles {      /* Line styles for get/setlinestyle */
    SOLID_LINE   = 0,
    DOTTED_LINE  = 1,
    CENTER_LINE  = 2,
    DASHED_LINE  = 3,
    USERBIT_LINE = 4,   /* User defined line style */
};

enum line_widths {      /* Line widths for get/setlinestyle */
    NORM_WIDTH  = 1,
    THICK_WIDTH = 3,
};

enum font_names {
    DEFAULT_FONT        = 0,    /* 8x8 bit mapped font */
    TRIPLEX_FONT        = 1,    /* "Stroked" fonts */
    SMALL_FONT          = 2,
    SANS_SERIF_FONT     = 3,
    GOTHIC_FONT         = 4,
    SCRIPT_FONT         = 5,        
    SIMPLEX_FONT        = 6,       
    TRIPLEX_SCR_FONT    = 7,
    COMPLEX_FONT        = 8,       
    EUROPEAN_FONT       = 9,  
    BOLD_FONT           = 10      
};

#define HORIZ_DIR   0   /* left to right */
#define VERT_DIR    1   /* bottom to top */

#define USER_CHAR_SIZE  0   /* user-defined char size */

enum fill_patterns {    /* Fill patterns for get/setfillstyle */
    EMPTY_FILL,         /* fills area in background color */
    SOLID_FILL,         /* fills area in solid fill color */
    LINE_FILL,          /* --- fill */
    LTSLASH_FILL,       /* /// fill */
    SLASH_FILL,         /* /// fill with thick lines */
    BKSLASH_FILL,       /* \\\ fill with thick lines */
    LTBKSLASH_FILL,     /* \\\ fill */
    HATCH_FILL,         /* light hatch fill */
    XHATCH_FILL,        /* heavy cross hatch fill */
    INTERLEAVE_FILL,    /* interleaving line fill */
    WIDE_DOT_FILL,      /* Widely spaced dot fill */
    CLOSE_DOT_FILL,     /* Closely spaced dot fill */
    USER_FILL           /* user defined fill */
};

enum putimage_ops {     /* BitBlt operators for putimage */
    COPY_PUT,           /* MOV */
    XOR_PUT,            /* XOR */
    OR_PUT,             /* OR  */
    AND_PUT,            /* AND */
    NOT_PUT             /* NOT */
};

enum text_just {        /* Horizontal and vertical justification
                           for settextjustify */
    LEFT_TEXT   = 0,
    CENTER_TEXT = 1,
    RIGHT_TEXT  = 2,

    BOTTOM_TEXT = 0,
     /* CENTER_TEXT = 1,  already defined above */
    TOP_TEXT    = 2
};


#define MAXCOLORS 15

struct palettetype {
    unsigned char size;
    signed char colors[MAXCOLORS+1];
};

struct linesettingstype {
    int linestyle;
    unsigned upattern;
    int thickness;
};

struct textsettingstype {
    int font;
    int direction;
    int charsize;
    int horiz;
    int vert;
};

struct fillsettingstype {
    int pattern;
    int color;
};

struct pointtype {
    int x, y;
};

struct viewporttype {
    int left, top, right, bottom;
    int clip;
};

struct arccoordstype {
    int x, y;
    int xstart, ystart, xend, yend;
};

#ifdef __cplusplus
extern "C" {
#endif
void       far _Cdecl arc(int __x, int __y, int __stangle, int __endangle,
              int __radius);
void       far _Cdecl bar(int __left, int __top, int __right, int __bottom);
void       far _Cdecl bar3d(int __left, int __top, int __right, int __bottom,
                int __depth, int __topflag);
void       far _Cdecl circle(int __x, int __y, int __radius);
void       far _Cdecl cleardevice(void);
void       far _Cdecl clearviewport(void);
void       far _Cdecl closegraph(void);
void       far _Cdecl detectgraph(int far *__graphdriver,int far *__graphmode);
void       far _Cdecl drawpoly(int __numpoints, const int far *__polypoints);
void       far _Cdecl ellipse(int __x, int __y, int __stangle, int __endangle,
                  int __xradius, int __yradius);
void       far _Cdecl fillellipse( int __x, int __y, int __xradius, int __yradius );
void       far _Cdecl fillpoly(int __numpoints, const int far *__polypoints);
void       far _Cdecl floodfill(int __x, int __y, int __border);
void       far _Cdecl getarccoords(struct arccoordstype far *__arccoords);
void       far _Cdecl getaspectratio(int far *__xasp, int far *__yasp);
int    far _Cdecl getbkcolor(void);
int    far _Cdecl getcolor(void);
struct palettetype far * far _Cdecl getdefaultpalette( void );
char *     far _Cdecl getdrivername( void );
void       far _Cdecl getfillpattern(char far *__pattern);
void       far _Cdecl getfillsettings(struct fillsettingstype far *__fillinfo);
int    far _Cdecl getgraphmode(void);
void       far _Cdecl getimage(int __left, int __top, int __right, int __bottom,
                   void far *__bitmap);
void       far _Cdecl getlinesettings(struct linesettingstype far *__lineinfo);
int    far _Cdecl getmaxcolor(void);
int    far _Cdecl getmaxmode(void);
int    far _Cdecl getmaxx(void);
int    far _Cdecl getmaxy(void);
char *     far _Cdecl getmodename( int __mode_number );
void       far _Cdecl getmoderange(int __graphdriver, int far *__lomode,
                   int far *__himode);
unsigned   far _Cdecl getpixel(int __x, int __y);
void       far _Cdecl getpalette(struct palettetype far *__palette);
int    far _Cdecl getpalettesize( void );
void       far _Cdecl gettextsettings(struct textsettingstype far *__texttypeinfo);
void       far _Cdecl getviewsettings(struct viewporttype far *__viewport);
int    far _Cdecl getx(void);
int    far _Cdecl gety(void);
void       far _Cdecl graphdefaults(void);
char *     far _Cdecl grapherrormsg(int __errorcode);
void       far _Cdecl _graphfreemem(void far *__ptr, unsigned __size);
void far * far _Cdecl _graphgetmem(unsigned __size);
int    far _Cdecl graphresult(void);
unsigned   far _Cdecl imagesize(int __left, int __top, int __right, int __bottom);
void       far _Cdecl initgraph(int  far *__graphdriver,
                int  far *__graphmode,
                const char far *__pathtodriver);
int    far _Cdecl installuserdriver( const char far *__name,
                int huge (*detect)(void) );
int    far _Cdecl installuserfont( const char far *__name );
void       far _Cdecl line(int __x1, int __y1, int __x2, int

Ah, yes, this is exactly the file I thought it was. This is for bit-graphics programming. You cannot use printf with it. (Well, you could, but it wouldn't be as nice or manipulatable as you'd like.) However, you can make your own little window for printing text.

typedef char FillPatternType[ 8 ];
typedef struct fillsettingstype FillSettingsType;

typedef struct {
  int left, top, width, height;
  } rect_t;

typedef struct {
  rect_t rect;
  int textcolor, bgcolor;
  } textwindow_t;

/* ----------------------------------------------------------------------
  Create a textwindow area and put a nice border around it.
  Preserves the fill pattern/style and fg and bg colors.
 */
textwindow_t create_textwindow(
  int left, int top, int width, int height,
  int bordercolor, int bgcolor, int textcolor
  ) {
  textwindow_t result;
  int right, bottom;
  int savecolor;
  FillPatternType savefillpattern, testfillpattern;
  FillSettingsType savefillsettings;
  int is_fillpattern_used;

  result.rect.left   = left +5;
  result.rect.top    = top  +5;
  result.rect.width  = width  -10;
  result.rect.height = height -10;
  result.textcolor   = textcolor;
  result.bgcolor     = bgcolor;

  right  = left +width  -1;
  bottom = top  +height -1;

  /* Preserve the fill pattern/settings */
  getfillsettings( &savefillsettings );
  getfillpattern( savefillpattern );
  memset( testfillpattern, 0xFF, sizeof( FillPatternType ) );
  is_fillpattern_used = memcmp(
    savefillpattern, testfillpattern, sizeof( FillPatternType )
    ) != 0;

  /* Clear the background */
  setfillstyle( SOLID_FILL, BLACK );
  bar( left, top, right, bottom );

  /* Draw the border */
  savecolor = getcolor();
  setcolor( bordercolor );

  arc( result.rect.left,  result.rect.top,     90, 180, 5 );
  arc( result.rect.left,  result.rect.bottom, 180, 270, 5 );
  arc( result.rect.right, result.rect.bottom, 270, 360, 5 );
  arc( result.rect.right, result.rect.top,      0,  90, 5 );

  line( left,  top,    left,  bottom );
  line( left,  bottom, right, bottom );
  line( right, bottom, right, top    );
  line( right, top,    left,  top    );

  setcolor( savecolor );

  /* Fill the interior */
  setfillstyle( SOLID_FILL, bgcolor );
  floodfill( result.rect.left, result.rect.top, bordercolor );

  /* Restore the fill pattern/settings */
  if (is_fillpattern_used) setfillpattern( savefillpattern, savefillsettings.color );
  else setfillstyle( savefillsettings.pattern, savefillsettings.color );

  return result;
  }

/* ----------------------------------------------------------------------
  Write a line of text to the textwindow, scrolling previous text
  upward. Writes using the current font settings and colors.
  Clips text to the textwindow.
 */
void print_line( textwindow_t *textwindow, char *text ) {
  int amount_to_scroll, height_of_region_to_save;
  void far *image;
  struct viewporttype saveviewport;
  int savefgcolor, savebgcolor;
  
  /* Scroll previous contents up */
  amount_to_scroll = textheight( text );
  height_of_region_to_save = textwindow->height -amount_to_scroll;
  if (height_of_region_to_save > 0) {
    image = malloc( imagesize(
      textwindow->left,
      textwindow->top,
      textwindow->left +textwindow->width -1,
      textwindow->top +height_of_region_to_save -1
      ) );
    if (image != NULL) {
      getimage(
        textwindow->left,
        textwindow->top +amount_to_scroll,
        textwindow->left +textwindow->width  -1,
        textwindow->top  +textwindow->height -1,
        image
        );
      putimage(
        textwindow->left,
        textwindow->top,
        image,
        COPY_PUT
        );
      free( image );
      }
    }

  /* Preserve the current viewport and colors */
  getviewsettings( &saveviewport );
  savefgcolor = getcolor();
  savebgcolor = getbkcolor();

  setcolor(   textwindow->textcolor );
  setbkcolor( textwindow->bgcolor   );

  /* Clear the new area */
  if (height_of_region_to_save < 0) height_of_region_to_save = 0;
  setviewport(
    textwindow->top +height_of_region_to_save,
    textwindow->left,
    textwindow->left +textwindow->width  -1,
    textwindow->top  +textwindow->height -1,
    TRUE
    );
  clearviewport();

  /* Draw the text string */
  outtextxy( 0, amount_to_scroll -textheight( text ), text );

  /* Restore the viewport and colors */
  setviewport(
    saveviewport.left,
    saveviewport.top,
    saveviewport.right,
    saveviewport.bottom,
    saveviewport.clip
    );
  setcolor(   savefgcolor );
  setbkcolor( savebgcolor );
  }

Now, once you have those handy little routines, you can use them to display your text.

#include <conio.h>
#include "graphics.h"

...

typedef struct {
  int rank;
  enum {spades, hearts, diamonds, clubs} suit;
  } card_t;

char *SUIT_NAMES[ 4 ] = { "Spades", "Hearts", "Diamonds", "Clubs" };

/* ----------------------------------------------------------------------
  Write a message of the form
    "Player x has thrown the card 1 of Spades"
  to the text window.
 */
void print_player_throws_card( textwindow_t *win, int player, card_t card ) {
  char s[ 100 ];
  sprintf(
    s,
    "Player %d has thrown the card %d of %s",
    player,
    card.rank,
    SUIT_NAMES[ card.suit ]
    );
  print_line( win, s );
  }

/* ----------------------------------------------------------------------
  Main program. Demonstrates the text window.
 */
int main() {
  textwindow_t win;
  card_t card = {1, spades};

  int graphdriver = EGA;
  int graphmode   = EGAHI;
  initgraph( &graphdriver, &graphmode, NULL );

  cleardevice();

  win = create_textwindow(
    100, 240, 440, 100,
    LIGHTCYAN, BLUE, YELLOW
    );

  print_line( win, "Hello world." );
  print_line( win, "" );
  print_player_throws_card( win, 1, card );
  print_line( win, "" );
  print_line( win, "Press the 'any' key." );
  getch();
  print_line( win, "." );
  print_line( win, "." );
  print_line( win, "." );
  print_line( win, "oh, yeah, do that again..." );
  getch();

  closegraph();
  return 0;
  }

Now, you should know that I just typed this in-- it has not been tested. (I don't have TurboC, so I'd have to convert it to Turbo Pascal to test... and I'd like to avoid that. I don't think I've made any egregious errors...)

This is to help you get comfortable with the graphics.h module. Obviously you'll want to change some things here and there. However, you should be warned that if you use this stuff you would be very wise to tell your professor that you got (a lot) of help with that little window (or "viewport"), and just modified some things to your liking. If you don't your professor will know it (seriously).

Enjoy.

lol
thanks a lot man ill post if i have major problems with it :)

This article has been dead for over six months. Start a new discussion instead.