⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap18.lst

📁 Borland C++ Builder The Complete Reference 例程源代码
💻 LST
字号:
listing 1
#include <conio.h> 
 
int main(void) 
{ 
  char holdstr[12]; 
  char *inpstr; 
 
  holdstr[0] = 10;  /* Only allow 10 characters */ 
  cprintf("Enter a string: "); 
  inpstr = cgets(holdstr); 
  cprintf("\r\nThe string:  \"%s\"  contains %d characters.\n", 
          inpstr, holdstr[1]); 
 
  return 0; 
}

listing 2
#include <conio.h> 
 
int main(void) 
{ 
  register int i; 
 
  gotoxy(10, 10); 
  cprintf("This is a test of the clreol() function."); 
  getch(); 
  gotoxy(10, 10); 
  clreol(); 
 
  for(i=0; i<20; i++) cprintf("Hello there\n\r"); 
  getch(); 
 
  /* clear the screen */ 
  clrscr(); 
 
  return 0; 
}

listing 3
#include <conio.h> 
 
int main(void) 
{ 
  /* This prints "this is a test" left justified 
     in 20 character field. 
  */ 
  cprintf("%-20s", "this is a test"); 
 
  /* This prints a float with 3 decimal places in a 10 
     character field. The output will be "    12.235". 
  */ 
  cprintf("%10.3f\n\r", 12.234657); 
 
  return 0; 
}

listing 4
#include <conio.h> 
 
void border(int, int, int, int); 
 
int main(void) 
{ 
  clrscr(); 
  /* create first window */ 
  window(3, 2, 40, 9); 
  border(3, 2, 40, 9); 
  gotoxy(1,1); 
  cputs("This line will be wrapped at the end of the window."); 
  getche(); 
 
  return 0; 
} 
 
/* Draws a border around a text window. */ 
void border(int startx, int starty, int endx, int endy) 
 { 
  register int i; 
 
  gotoxy(1, 1); 
  for(i=0; i<=endx-startx; i++) 
    putch('-'); 
 
  gotoxy(1, endy-starty); 
  for(i=0; i<=endx-startx; i++) 
    putch('-'); 
 
  for(i=2; i<endy-starty; i++) { 
    gotoxy(1, i); 
    putch('|'); 
    gotoxy(endx-startx+1, i); 
    putch('|'); 
  } 
}

listing 5
char str[80]; 
float f; 
 
cscanf("%s%f", str, &f);

listing 6
#include <conio.h> 
 
int main(void) 
{ 
  register int i; 
 
  clrscr(); 
 
  for(i=0; i<24; i++) cprintf("line %d\n\r", i); 
  getch(); 
  gotoxy(1, 4); 
  delline(); 
 
  getch(); 
 
  return 0; 
}

listing 7
buf = (char *)malloc(10 * 10 *2); 
gettext(10, 10, 20, 20, buf);

listing 8
struct text_info i; 
gettextinfo(&i);

listing 9
#include <conio.h> 
 
int main(void) 
{ 
  register int i, j; 
 
  clrscr(); 
  /* print diagonal Xs */ 
  for(i=1, j=1; j<24; i+=3, j++) { 
    gotoxy(i, j); 
    cprintf("X"); 
  } 
   getche(); 
   clrscr(); 
 
   return 0; 
}

listing 10
highvideo();

listing 11
#include <conio.h> 
 
int main(void) 
{ 
  register int i; 
 
  clrscr(); 
 
  for(i=1; i<24; i++) { 
    gotoxy(1, i); 
    cprintf("This is line %d\n\r", i); 
  } 
  getche(); 
  gotoxy(1, 10); 
  insline(); 
  getch(); 
 
  return 0; 
}

listing 12
lowvideo();

listing 13
movetext(1, 1, 8, 8, 10, 10);

listing 14
normvideo();

listing 15
buf = (char *) malloc(10 * 10 *2); 
gettext(10, 10, 20, 20, buf); 
puttext(0, 0, 30, 30, buf);

listing 16
textattr(RED | BLUE*16);

listing 17
textbackground(CYAN);

listing 18
textcolor(BLINK);

listing 19
textmode(C80);

listing 20
int xpos, ypos; 
 
xpos = wherex(); 
ypos = wherey();

listing 21
window(10, 10, 60, 15); 
gotoxy(2, 3); 
cprintf("at location 2, 3");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -