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... =\

Member Avatar for iamthwee

Maybe you could use clrscr() in turbo c. I don't know what you want to do?

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.

like "player 1 has thrown the card 4 of ♥". **

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

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.