/* ===== CFUNK
  while ( (ch = getchar()) != EOF );
*/
#include <dos.h>
#include <stdio.h>
#include <conio.h>

void clsxy( int x1, int y1, int x2, int y2 );
void gotoxy( int x, int y );
char *repeat( int k, char c);
void warten( void );
char *zentr( char *s);




#ifndef ZEILENLAENGE
#define ZEILENLAENGE 80
char buf[ZEILENLAENGE] ;
char buf1[ZEILENLAENGE] ;
#endif


////////////////////////////////////////////////
void clsxy( int x1, int y1, int x2, int y2 )
//  lscht Screen von x bis y, BIOS-Intr. 0x10,
//            Unterfunktion 6 (in AH bergeben)
//  dos.h
{
  union REGS *inregs, *outregs, unionregs;
  int intno;

  inregs  = &unionregs;
  outregs = &unionregs;
  intno   = 0x10;
  inregs -> h.ah =  6;
  inregs -> h.al =  0;
  inregs -> h.bh =  7;
  inregs -> h.ch = x1;
  inregs -> h.cl = y1;
  inregs -> h.dh = x2;
  inregs -> h.dl = y2;
  int86( intno, inregs, outregs );
}

//////////////////////////////////////////////////////
void gotoxy( int x, int y )
//  setzt Cursor an Pos. x(= Zeile) bis  y(= Spalte)
//            Unterfunktion 2 (in AH bergeben)
//  dos.h
{
  union REGS *inregs, *outregs, unionregs;
  int intno;

  inregs  = &unionregs;
  outregs = &unionregs;
  intno   = 0x10;
  inregs -> h.ah = 2;
  inregs -> h.bh = 0;
  inregs -> h.dh = x;
  inregs -> h.dl = y;
  int86( intno, inregs, outregs );
}


//////////////////////////////////////////////////////
void warten( void )
//    wartet auf Tastendruck
//    conio.h
{
  getch();
}


//////////////////////////////////////////////////////
char *repeat( int k, char c)
//    repeat(): Wiederholt Zeichen , schreibt sie in einen String,
//    bentigen ZEILENLAENGE, buf, buf1
{
  int i;
  for ( i = 0; i < ZEILENLAENGE ; buf[ i++] = '\0' );
  for (i = 1; i <= k; i++)
    strcat( buf, &c );
  return( buf );
}

/////////////////////////////////////////////////
char *zentr( char *s)
//    zentr():  Gibt String zentriert in Zeilenmitte aus, hierfr:
//    repeat(): Wiederholt Zeichen , schreibt sie in einen String,
//    bentigen ZEILENLAENGE, buf, buf1
{
  int i, sl, leer;
  sl = strlen(s);
  leer = (ZEILENLAENGE - sl) / 2 ;
  repeat( leer, '-');
  strcpy( buf1, buf);
  strcat( buf1, s );
  if ( ((ZEILENLAENGE - sl) % 2 ) )
    repeat( leer+1, '-');
  strcat( buf1, buf);
  return(buf1);
}








main()
{
  int i;
  char s[] = "Abracadabra",
       s2[ZEILENLAENGE];
  strcpy( s2, zentr( s) ) ;
  puts( s2 );
  puts("\n");
  clsxy( 2, 10, 20, 30 );
  gotoxy( 21, 14);
  warten();
}


