ºìÁªLinuxÃÅ»§
Linux°ïÖú

CÓïÑԿ⺯Êý---unix³£ÓÃϵͳµ÷ÓÃ---ʹÓÃ˵Ã÷£¨ÉÏ£©

·¢²¼Ê±¼ä:2006-08-21 15:55:35À´Ô´:ºìÁª×÷Õß:hfh08
¡¾ËµÃ÷¡¿
Ò»¹²·ÖΪ3¸öС½Ú£¬1С½Ú¸ø¶¨Ò»¸öÁ¬½Ó£¬¸ÃÁ¬½Ó¸øÁËһЩ³£Óñê×¼cµÄº¯ÊýʹÓÃ˵Ã÷£¬µ«ÊDz»¹»È«Ãæ¡£2С½á°´×Öĸ˳ÐòÅÅÁУ¬¼¸ºõ¸²¸ÇÁËcÖг£Óõĺ¯Êý£¬Í¬Ê±ÓÐЩº¯Êý²»ÔÚunixϵͳÖÐÖ§³ÖÁË¡£3С½ÚÃèÊöÁËunixϵͳÖг£ÓÃϵͳµ÷ÓõÄʹÓÃ˵Ã÷¡£
1¡¢¡¾ÏÂÃæÕâ¸öÁ¬½Ó¸ø³öÁËһЩc¿âµÄº¯Êý˵Ã÷ʹÓÃÀý³Ì£¬µ«ÊDz»¹»È«Ã棬¿ÉÒÔ×÷Ϊ²Î¿¼¡¿
2¡¢¡¾Èç϶ÔCÓïÑԿ⺯Êý°´×Öĸ˳ÐòÃèÊö,Èç¹ûÉÏÃæÁ¬½ÓÖÐÕÒ²»µ½£¬¿ÉÒÔµ½ÕâÀï²éÕÒµ½£¬ÐèҪ˵Ã÷µÄÊÇ£¬ÓÐЩº¯ÊýÔÚеÄlibcÖÐÒѾ­²»ÌṩÁË£¬Èç¹ûÒª²éÕÒunixϵͳ³£ÓÃϵͳµ÷Óú¯ÊýʹÓÃ˵Ã÷£¬Ç뵽С½Ú3²éÕÒ¡¿

º¯ÊýÃû: abort
¹¦ ÄÜ: Òì³£ÖÕÖ¹Ò»¸ö½ø³Ì
ÓÃ ·¨: void abort(void);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
printf("Calling abort()\n");
abort();
return 0; /* This is never reached */
}
º¯ÊýÃû: abs
¹¦ ÄÜ: ÇóÕûÊýµÄ¾ø¶ÔÖµ
ÓÃ ·¨: int abs(int i);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
int number = -1234;
printf("number: %d absolute value: %d\n", number, abs(number));
return 0;
}
º¯ÊýÃû: absread, abswirte
¹¦ ÄÜ: ¾ø¶Ô´ÅÅÌÉÈÇø¶Á¡¢Ð´Êý¾Ý
ÓÃ ·¨: int absread(int drive, int nsects, int sectno, void *buffer);
int abswrite(int drive, int nsects, in tsectno, void *buffer);
³ÌÐòÀý:
/* absread example */
#include ;
#include ;
#include ;
#include ;
int main(void)
{
int i, strt, ch_out, sector;
char buf[512];
printf("Insert a diskette into drive A and press any key\n");
getch();
sector = 0;
if (absread(0, 1, sector, &buf) != 0)
{
perror("Disk problem");
exit(1);
}
printf("Read OK\n");
strt = 3;
for (i=0; i<80; i++)
{
ch_out = buf[strt+i];
putchar(ch_out);
}
printf("\n");
return(0);
}
º¯ÊýÃû: access
¹¦ ÄÜ: È·¶¨ÎļþµÄ·ÃÎÊȨÏÞ
ÓÃ ·¨: int access(const char *filename, int amode);
³ÌÐòÀý:
#include ;
#include ;
int file_exists(char *filename);
int main(void)
{
printf("Does NOTEXIST.FIL exist: %s\n",
file_exists("NOTEXISTS.FIL") ? "YES" : "NO");
return 0;
}
int file_exists(char *filename)
{
return (access(filename, 0) == 0);
}
º¯ÊýÃû: acos
¹¦ ÄÜ: ·´ÓàÏÒº¯Êý
ÓÃ ·¨: double acos(double x);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
double result;
double x = 0.5;
result = acos(x);
printf("The arc cosine of %lf is %lf\n", x, result);
return 0;
}
º¯ÊýÃû: allocmem
¹¦ ÄÜ: ·ÖÅäDOS´æ´¢¶Î
ÓÃ ·¨: int allocmem(unsigned size, unsigned *seg);
³ÌÐòÀý:
#include ;
#include ;
#include ;
int main(void)
{
unsigned int size, segp;
int stat;
size = 64; /* (64 x 16) = 1024 bytes */
stat = allocmem(size, &segp);
if (stat == -1)
printf("Allocated memory at segment: %x\n", segp);
else
printf("Failed: maximum number of paragraphs available is %u\n",
stat);
return 0;
}
º¯ÊýÃû: arc
¹¦ ÄÜ: »­Ò»»¡Ïß
ÓÃ ·¨: void far arc(int x, int y, int stangle, int endangle, int radius);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
int stangle = 45, endangle = 135;
int radius = 100;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult(); /* an error occurred */
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());
/* draw arc */
arc(midx, midy, stangle, endangle, radius);
/* clean up */
getch();
closegraph();
return 0;
}
º¯ÊýÃû: asctime
¹¦ ÄÜ: ת»»ÈÕÆÚºÍʱ¼äΪASCIIÂë
ÓÃ ·¨: char *asctime(const struct tm *tblock);
³ÌÐòÀý:
#include ;
#include ;
#include ;
int main(void)
{
struct tm t;
char str[80];
/* sample loading of tm structure */
t.tm_sec = 1; /* Seconds */
t.tm_min = 30; /* Minutes */
t.tm_hour = 9; /* Hour */
t.tm_mday = 22; /* Day of the Month */
t.tm_mon = 11; /* Month */
t.tm_year = 56; /* Year - does not include century */
t.tm_wday = 4; /* Day of the week */
t.tm_yday = 0; /* Does not show in asctime */
t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */
/* converts structure to null terminated
string */
strcpy(str, asctime(&t));
printf("%s\n", str);
return 0;
}
º¯ÊýÃû: asin
¹¦ ÄÜ: ·´ÕýÏÒº¯Êý
ÓÃ ·¨: double asin(double x);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
double result;
double x = 0.5;
result = asin(x);
printf("The arc sin of %lf is %lf\n", x, result);
return(0);
}
º¯ÊýÃû: assert
¹¦ ÄÜ: ²âÊÔÒ»¸öÌõ¼þ²¢¿ÉÄÜʹ³ÌÐòÖÕÖ¹
ÓÃ ·¨: void assert(int test);
³ÌÐòÀý:
#include ;
#include ;
#include ;
struct ITEM {
int key;
int value;
};
/* add item to list, make sure list is not null */
void additem(struct ITEM *itemptr) {
assert(itemptr != NULL);
/* add item to list */
}
int main(void)
{
additem(NULL);
return 0;
}
º¯ÊýÃû: atan
¹¦ ÄÜ: ·´ÕýÇк¯Êý
ÓÃ ·¨: double atan(double x);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
double result;
double x = 0.5;
result = atan(x);
printf("The arc tangent of %lf is %lf\n", x, result);
return(0);
}
º¯ÊýÃû: atan2
¹¦ ÄÜ: ¼ÆËãY/XµÄ·´ÕýÇÐÖµ
ÓÃ ·¨: double atan2(double y, double x);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
double result;
double x = 90.0, y = 45.0;
result = atan2(y, x);
printf("The arc tangent ratio of %lf is %lf\n", (y / x), result);
return 0;
}
º¯ÊýÃû: atexit
¹¦ ÄÜ: ×¢²áÖÕÖ¹º¯Êý
ÓÃ ·¨: int atexit(atexit_t func);
³ÌÐòÀý:
#include ;
#include ;
void exit_fn1(void)
{
printf("Exit function #1 called\n");
}
void exit_fn2(void)
{
printf("Exit function #2 called\n");
}
int main(void)
{
/* post exit function #1 */
atexit(exit_fn1);
/* post exit function #2 */
atexit(exit_fn2);
return 0;
}
º¯ÊýÃû: atof
¹¦ ÄÜ: °Ñ×Ö·û´®×ª»»³É¸¡µãÊý
ÓÃ ·¨: double atof(const char *nptr);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
float f;
char *str = "12345.67";
f = atof(str);
printf("string = %s float = %f\n", str, f);
return 0;
}
º¯ÊýÃû: atoi
¹¦ ÄÜ: °Ñ×Ö·û´®×ª»»³É³¤ÕûÐÍÊý
ÓÃ ·¨: int atoi(const char *nptr);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
int n;
char *str = "12345.67";
n = atoi(str);
printf("string = %s integer = %d\n", str, n);
return 0;
}
º¯ÊýÃû: atol
¹¦ ÄÜ: °Ñ×Ö·û´®×ª»»³É³¤ÕûÐÍÊý
ÓÃ ·¨: long atol(const char *nptr);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
long l;
char *str = "98765432";
l = atol(lstr);
printf("string = %s integer = %ld\n", str, l);
return(0);
}
º¯ÊýÃû: bar
¹¦ ÄÜ: »­Ò»¸ö¶þάÌõÐÎͼ
ÓÃ ·¨: void far bar(int left, int top, int right, int bottom);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy, i;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
/* loop through the fill patterns */
for (i=SOLID_FILL; i{
/* set the fill style */
setfillstyle(i, getmaxcolor());
/* draw the bar */
bar(midx-50, midy-50, midx+50,
midy+50);
getch();
}
/* clean up */
closegraph();
return 0;
}
º¯ÊýÃû: bar3d
¹¦ ÄÜ: »­Ò»¸öÈýάÌõÐÎͼ
ÓÃ ·¨: void far bar3d(int left, int top, int right, int bottom,
int depth, int topflag);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy, i;
/* initialize graphics, local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with error code */
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
/* loop through the fill patterns */
for (i=EMPTY_FILL; i{
/* set the fill style */
setfillstyle(i, getmaxcolor());
/* draw the 3-d bar */
bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1);
getch();
}
/* clean up */
closegraph();
return 0;
}
º¯ÊýÃû: bdos
¹¦ ÄÜ: DOSϵͳµ÷ÓÃ
ÓÃ ·¨: int bdos(int dosfun, unsigned dosdx, unsigned dosal);
³ÌÐòÀý:
#include ;
#include ;
/* Get current drive as 'A', 'B', ... */
char current_drive(void)
{
char curdrive;
/* Get current disk as 0, 1, ... */
curdrive = bdos(0x19, 0, 0);
return('A' + curdrive);
}
int main(void)
{
printf("The current drive is %c:\n", current_drive());
return 0;
}
º¯ÊýÃû: bdosptr
¹¦ ÄÜ: DOSϵͳµ÷ÓÃ
ÓÃ ·¨: int bdosptr(int dosfun, void *argument, unsigned dosal);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
#include ;
#include ;
#define BUFLEN 80
int main(void)
{
char buffer[BUFLEN];
int test;
printf("Enter full pathname of a directory\n");
gets(buffer);
test = bdosptr(0x3B,buffer,0);
if(test)
{
printf("DOS error message: %d\n", errno);
/* See errno.h for error listings */
exit (1);
}
getcwd(buffer, BUFLEN);
printf("The current directory is: %s\n", buffer);
return 0;
}
º¯ÊýÃû: bioscom
¹¦ ÄÜ: ´®ÐÐI/OͨÐÅ
ÓÃ ·¨: int bioscom(int cmd, char abyte, int port);
³ÌÐòÀý:
#include ;
#include ;
#define COM1 0
#define DATA_READY 0x100
#define TRUE 1
#define FALSE 0
#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)
int main(void)
{
int in, out, status, DONE = FALSE;
bioscom(0, SETTINGS, COM1);
cprintf("... BIOSCOM [ESC] to exit ...\n");
while (!DONE)
{
status = bioscom(3, 0, COM1);
if (status & DATA_READY)
if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)
putch(out);
if (kbhit())
{
if ((in = getch()) == '\x1B')
DONE = TRUE;
bioscom(1, in, COM1);
}
}
return 0;
}
º¯ÊýÃû: biosdisk
¹¦ ÄÜ: ÈíÓ²ÅÌI/O
ÓÃ ·¨: int biosdisk(int cmd, int drive, int head, int track, int sector
int nsects, void *buffer);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
int result;
char buffer[512];
printf("Testing to see if drive a: is ready\n");
result = biosdisk(4,0,0,0,0,1,buffer);
result &= 0x02;
(result) ? (printf("Drive A: Ready\n")) :
(printf("Drive A: Not Ready\n"));
return 0;
}
º¯ÊýÃû: biosequip
¹¦ ÄÜ: ¼ì²éÉ豸
ÓÃ ·¨: int biosequip(void);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
int result;
char buffer[512];
printf("Testing to see if drive a: is ready\n");
result = biosdisk(4,0,0,0,0,1,buffer);
result &= 0x02;
(result) ? (printf("Drive A: Ready\n")) :
(printf("Drive A: Not Ready\n"));
return 0;
}
º¯ÊýÃû: bioskey
¹¦ ÄÜ: Ö±½ÓʹÓÃBIOS·þÎñµÄ¼üÅ̽ӿÚ
ÓÃ ·¨: int bioskey(int cmd);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#define RIGHT 0x01
#define LEFT 0x02
#define CTRL 0x04
#define ALT 0x08
int main(void)
{
int key, modifiers;
/* function 1 returns 0 until a key is pressed */
while (bioskey(1) == 0);
/* function 0 returns the key that is waiting */
key = bioskey(0);
/* use function 2 to determine if shift keys were used */
modifiers = bioskey(2);
if (modifiers)
{
printf("[");
if (modifiers & RIGHT) printf("RIGHT");
if (modifiers & LEFT) printf("LEFT");
if (modifiers & CTRL) printf("CTRL");
if (modifiers & ALT) printf("ALT");
printf("]");
}
/* print out the character read */
if (isalnum(key & 0xFF))
printf("'%c'\n", key);
else
printf("%#02x\n", key);
return 0;
}
º¯ÊýÃû: biosmemory
¹¦ ÄÜ: ·µ»Ø´æ´¢¿é´óС
ÓÃ ·¨:int biosmemory(void);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
int memory_size;
memory_size = biosmemory(); /* returns value up to 640K */
printf("RAM size = %dK\n",memory_size);
return 0;
}
º¯ÊýÃû: biosprint
¹¦ ÄÜ: Ö±½ÓʹÓÃBIOS·þÎñµÄ´òÓ¡»úI/O
ÓÃ ·¨: int biosprint(int cmd, int byte, int port);
³ÌÐòÀý:
#include ;
#include ;
#include ;
int main(void)
{
#define STATUS 2 /* printer status command */
#define PORTNUM 0 /* port number for LPT1 */
int status, abyte=0;
printf("Please turn off your printer. Press any key to continue\n");
getch();
status = biosprint(STATUS, abyte, PORTNUM);
if (status & 0x01)
printf("Device time out.\n");
if (status & 0x08)
printf("I/O error.\n");
if (status & 0x10)
printf("Selected.\n");
if (status & 0x20)
printf("Out of paper.\n");
if (status & 0x40)
printf("Acknowledge.\n");
if (status & 0x80)
printf("Not busy.\n");
return 0;
}
º¯ÊýÃû: biostime
¹¦ ÄÜ: ¶ÁÈ¡»òÉèÖÃBIOSʱ¼ä
ÓÃ ·¨: long biostime(int cmd, long newtime);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
long bios_time;
clrscr();
cprintf("The number of clock ticks since midnight is:\r\n");
cprintf("The number of seconds since midnight is:\r\n");
cprintf("The number of minutes since midnight is:\r\n");
cprintf("The number of hours since midnight is:\r\n");
cprintf("\r\nPress any key to quit:");
while(!kbhit())
{
bios_time = biostime(0, 0L);
gotoxy(50, 1);
cprintf("%lu", bios_time);
gotoxy(50, 2);
cprintf("%.4f", bios_time / CLK_TCK);
gotoxy(50, 3);
cprintf("%.4f", bios_time / CLK_TCK / 60);
gotoxy(50, 4);
cprintf("%.4f", bios_time / CLK_TCK / 3600);
}
return 0;
}
º¯ÊýÃû: brk
¹¦ ÄÜ: ¸Ä±äÊý¾Ý¶Î¿Õ¼ä·ÖÅä
ÓÃ ·¨: int brk(void *endds);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
char *ptr;
printf("Changing allocation with brk()\n");
ptr = malloc(1);
printf("Before brk() call: %lu bytes free\n", coreleft());
brk(ptr+1000);
printf(" After brk() call: %lu bytes free\n", coreleft());
return 0;
}
º¯ÊýÃû: bsearch
¹¦ ÄÜ: ¶þ·Ö·¨ËÑË÷
ÓÃ ·¨: void *bsearch(const void *key, const void *base, size_t *nelem,
size_t width, int(*fcmp)(const void *, const *));
³ÌÐòÀý:
#include ;
#include ;
#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0]))
int numarray[] = {123, 145, 512, 627, 800, 933};
int numeric (const int *p1, const int *p2)
{
return(*p1 - *p2);
}
int lookup(int key)
{
int *itemptr;
/* The cast of (int(*)(const void *,const void*))
is needed to avoid a type mismatch error at
compile time */
itemptr = bsearch (&key, numarray, NELEMS(numarray),
sizeof(int), (int(*)(const void *,const void *))numeric);
return (itemptr != NULL);
}
int main(void)
{
if (lookup(512))
printf("512 is in the table.\n");
else
printf("512 isn't in the table.\n");
return 0;
}
º¯ÊýÃû: cabs
¹¦ ÄÜ: ¼ÆË㸴ÊýµÄ¾ø¶ÔÖµ
ÓÃ ·¨: double cabs(struct complex z);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
struct complex z;
double val;
z.x = 2.0;
z.y = 1.0;
val = cabs(z);
printf("The absolute value of %.2lfi %.2lfj is %.2lf", z.x, z.y, val);
return 0;
}
º¯ÊýÃû: calloc
¹¦ ÄÜ: ·ÖÅäÖ÷´æ´¢Æ÷
ÓÃ ·¨: void *calloc(size_t nelem, size_t elsize);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
char *str = NULL;
/* allocate memory for string */
str = calloc(10, sizeof(char));
/* copy "Hello" into string */
strcpy(str, "Hello");
/* display string */
printf("String is %s\n", str);
/* free memory */
free(str);
return 0;
}
º¯ÊýÃû: ceil
¹¦ ÄÜ: ÏòÉÏÉáÈë
ÓÃ ·¨: double ceil(double x);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
double number = 123.54;
double down, up;
down = floor(number);
up = ceil(number);
printf("original number %5.2lf\n", number);
printf("number rounded down %5.2lf\n", down);
printf("number rounded up %5.2lf\n", up);
return 0;
}
º¯ÊýÃû: cgets
¹¦ ÄÜ: ´Ó¿ØÖÆ̨¶Á×Ö·û´®
ÓÃ ·¨: char *cgets(char *str);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
char buffer[83];
char *p;
/* There's space for 80 characters plus the NULL terminator */
buffer[0] = 81;
printf("Input some chars:");
p = cgets(buffer);
printf("\ncgets read %d characters: \"%s\"\n", buffer[1], p);
printf("The returned pointer is %p, buffer[0] is at %p\n", p, &buffer);
/* Leave room for 5 characters plus the NULL terminator */
buffer[0] = 6;
printf("Input some chars:");
p = cgets(buffer);
printf("\ncgets read %d characters: \"%s\"\n", buffer[1], p);
printf("The returned pointer is %p, buffer[0] is at %p\n", p, &buffer);
return 0;
}
º¯ÊýÃû: chdir
¹¦ ÄÜ: ¸Ä±ä¹¤×÷Ŀ¼
ÓÃ ·¨: int chdir(const char *path);
³ÌÐòÀý:
#include ;
#include ;
#include ;
char old_dir[MAXDIR];
char new_dir[MAXDIR];
int main(void)
{
if (getcurdir(0, old_dir))
{
perror("getcurdir()");
exit(1);
}
printf("Current directory is: \\%s\n", old_dir);
if (chdir("\\"))
{
perror("chdir()");
exit(1);
}
if (getcurdir(0, new_dir))
{
perror("getcurdir()");
exit(1);
}
printf("Current directory is now: \\%s\n", new_dir);
printf("\nChanging back to orignal directory: \\%s\n", old_dir);
if (chdir(old_dir))
{
perror("chdir()");
exit(1);
}
return 0;
}
º¯ÊýÃû: _chmod, chmod
¹¦ ÄÜ: ¸Ä±äÎļþµÄ·ÃÎÊ·½Ê½
ÓÃ ·¨: int chmod(const char *filename, int permiss);
³ÌÐòÀý:
#include ;
#include ;
#include ;
void make_read_only(char *filename);
int main(void)
{
make_read_only("NOTEXIST.FIL");
make_read_only("MYFILE.FIL");
return 0;
}
void make_read_only(char *filename)
{
int stat;
stat = chmod(filename, S_IREAD);
if (stat)
printf("Couldn't make %s read-only\n", filename);
else
printf("Made %s read-only\n", filename);
}
º¯ÊýÃû: chsize
¹¦ ÄÜ: ¸Ä±äÎļþ´óС
ÓÃ ·¨: int chsize(int handle, long size);
³ÌÐòÀý:
#include ;
#include ;
#include ;
int main(void)
{
int handle;
char buf[11] = "0123456789";
/* create text file containing 10 bytes */
handle = open("DUMMY.FIL", O_CREAT);
write(handle, buf, strlen(buf));
/* truncate the file to 5 bytes in size */
chsize(handle, 5);
/* close the file */
close(handle);
return 0;
}
º¯ÊýÃû: circle
¹¦ ÄÜ: ÔÚ¸ø¶¨°ë¾¶ÒÔ(x, y)ΪԲÐÄ»­Ô²
ÓÃ ·¨: void far circle(int x, int y, int radius);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
int radius = 100;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());
/* draw the circle */
circle(midx, midy, radius);
/* clean up */
getch();
closegraph();
return 0;
}
º¯ÊýÃû: cleardevice
¹¦ ÄÜ: Çå³ýͼÐÎÆÁÄ»
ÓÃ ·¨: void far cleardevice(void);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());
/* for centering screen messages */
settextjustify(CENTER_TEXT, CENTER_TEXT);
/* output a message to the screen */
outtextxy(midx, midy, "press any key to clear the screen:");
/* wait for a key */
getch();
/* clear the screen */
cleardevice();
/* output another message */
outtextxy(midx, midy, "press any key to quit:");
/* clean up */
getch();
closegraph();
return 0;
}
º¯ÊýÃû: clearerr
¹¦ ÄÜ: ¸´Î»´íÎó±êÖ¾
ÓÃ ·¨:void clearerr(FILE *stream);
³ÌÐòÀý:
#include ;
int main(void)
{
FILE *fp;
char ch;
/* open a file for writing */
fp = fopen("DUMMY.FIL", "w");
/* force an error condition by attempting to read */
ch = fgetc(fp);
printf("%c\n",ch);
if (ferror(fp))
{
/* display an error message */
printf("Error reading from DUMMY.FIL\n");
/* reset the error and EOF indicators */
clearerr(fp);
}
fclose(fp);
return 0;
}
º¯ÊýÃû: clearviewport
¹¦ ÄÜ: Çå³ýͼÐÎÊÓÇø
ÓÃ ·¨: void far clearviewport(void);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
#define CLIP_ON 1 /* activates clipping in viewport */
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int ht;
/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
setcolor(getmaxcolor());
ht = textheight("W");
/* message in default full-screen viewport */
outtextxy(0, 0, "* <-- (0, 0) in default viewport");
/* create a smaller viewport */
setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON);
/* display some messages */
outtextxy(0, 0, "* <-- (0, 0) in smaller viewport");
outtextxy(0, 2*ht, "Press any key to clear viewport:");
/* wait for a key */
getch();
/* clear the viewport */
clearviewport();
/* output another message */
outtextxy(0, 0, "Press any key to quit:");
/* clean up */
getch();
closegraph();
return 0;
}
º¯ÊýÃû: _close, close
¹¦ ÄÜ: ¹Ø±ÕÎļþ¾ä±ú
ÓÃ ·¨: int close(int handle);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
main()
{
int handle;
char buf[11] = "0123456789";
/* create a file containing 10 bytes */
handle = open("NEW.FIL", O_CREAT);
if (handle >; -1)
{
write(handle, buf, strlen(buf));
/* close the file */
close(handle);
}
else
{
printf("Error opening file\n");
}
return 0;
}
º¯ÊýÃû: clock
¹¦ ÄÜ: È·¶¨´¦ÀíÆ÷ʱ¼ä
ÓÃ ·¨: clock_t clock(void);
³ÌÐòÀý:
#include ;
#include ;
#include ;
int main(void)
{
clock_t start, end;
start = clock();
delay(2000);
end = clock();
printf("The time was: %f\n", (end - start) / CLK_TCK);
return 0;
}
º¯ÊýÃû: closegraph
¹¦ ÄÜ: ¹Ø±ÕͼÐÎϵͳ
ÓÃ ·¨: void far closegraph(void);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int x, y;
/* initialize graphics mode */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk) /* an error
occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
x = getmaxx() / 2;
y = getmaxy() / 2;
/* output a message */
settextjustify(CENTER_TEXT, CENTER_TEXT);
outtextxy(x, y, "Press a key to close the graphics system:");
/* wait for a key */
getch();
/* closes down the graphics system */
closegraph();
printf("We're now back in text mode.\n");
printf("Press any key to halt:");
getch();
return 0;
}
º¯ÊýÃû: clreol
¹¦ ÄÜ: ÔÚÎı¾´°¿ÚÖÐÇå³ý×Ö·ûµ½ÐÐÄ©
ÓÃ ·¨: void clreol(void);
³ÌÐòÀý:
#include ;
int main(void)
{
clrscr();
cprintf("The function CLREOL clears all characters from the\r\n");
cprintf("cursor position to the end of the line within the\r\n");
cprintf("current text window, without moving the cursor.\r\n");
cprintf("Press any key to continue . . .");
gotoxy(14, 4);
getch();
clreol();
getch();
return 0;
}
º¯ÊýÃû: clrscr
¹¦ ÄÜ: Çå³ýÎı¾Ä£Ê½´°¿Ú
ÓÃ ·¨: void clrscr(void);
³ÌÐòÀý:
#include ;
int main(void)
{
int i;
clrscr();
for (i = 0; i < 20; i++)
cprintf("%d\r\n", i);
cprintf("\r\nPress any key to clear screen");
getch();
clrscr();
cprintf("The screen has been cleared!");
getch();
return 0;
}
º¯ÊýÃû: coreleft
¹¦ ÄÜ: ·µ»ØδʹÓÃÄÚ´æµÄ´óС
ÓÃ ·¨: unsigned coreleft(void);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
printf("The difference between the highest allocated block and\n");
printf("the top of the heap is: %lu bytes\n", (unsigned long) coreleft());
return 0;
}
º¯ÊýÃû: cos
¹¦ ÄÜ: ÓàÏÒº¯Êý
ÓÃ ·¨: double cos(double x);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
double result;
double x = 0.5;
result = cos(x);
printf("The cosine of %lf is %lf\n", x, result);
return 0;
}
º¯ÊýÃû: cosh
¹¦ ÄÜ: Ë«ÇúÓàÏÒº¯Êý
ÓÃ ·¨: dluble cosh(double x);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
double result;
double x = 0.5;
result = cosh(x);
printf("The hyperboic cosine of %lf is %lf\n", x, result);
return 0;
}
º¯ÊýÃû: country
¹¦ ÄÜ: ·µ»ØÓë¹ú¼ÒÓйصÄÐÅÏ¢
ÓÃ ·¨: struct COUNTRY *country(int countrycode, struct country *country);
³ÌÐòÀý:
#include ;
#include ;
#define USA 0
int main(void)
{
struct COUNTRY country_info;
country(USA, &country_info);
printf("The currency symbol for the USA is: %s\n",
return 0;
}
º¯ÊýÃû: cprintf
¹¦ ÄÜ: Ë͸ñʽ»¯Êä³öÖÁÆÁÄ»
ÓÃ ·¨: int cprintf(const char *format[, argument, ...]);
³ÌÐòÀý:
#include ;
int main(void)
{
/* clear the screen */
clrscr();
/* create a text window */
window(10, 10, 80, 25);
/* output some text in the window */
cprintf("Hello world\r\n");
/* wait for a key */
getch();
return 0;
}
º¯ÊýÃû: cputs
¹¦ ÄÜ: д×Ö·ûµ½ÆÁÄ»
ÓÃ ·¨: void cputs(const char *string);
³ÌÐòÀý:
#include ;
int main(void)
{
/* clear the screen */
clrscr();
/* create a text window */
window(10, 10, 80, 25);
/* output some text in the window */
cputs("This is within the window\r\n");
/* wait for a key */
getch();
return 0;
}
º¯ÊýÃû: _creat creat
¹¦ ÄÜ: ´´½¨Ò»¸öÐÂÎļþ»òÖØдһ¸öÒÑ´æÔÚµÄÎļþ
ÓÃ ·¨: int creat (const char *filename, int permiss);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
int handle;
char buf[11] = "0123456789";
/* change the default file mode from text to binary */
_fmode = O_BINARY;
/* create a binary file for reading and writing */
handle = creat("DUMMY.FIL", S_IREAD | S_IWRITE);
/* write 10 bytes to the file */
write(handle, buf, strlen(buf));
/* close the file */
close(handle);
return 0;
}
º¯ÊýÃû: creatnew
¹¦ ÄÜ: ´´½¨Ò»¸öÐÂÎļþ
ÓÃ ·¨: int creatnew(const char *filename, int attrib);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
#include ;
int main(void)
{
int handle;
char buf[11] = "0123456789";
/* attempt to create a file that doesn't already exist */
handle = creatnew("DUMMY.FIL", 0);
if (handle == -1)
printf("DUMMY.FIL already exists.\n");
else
{
printf("DUMMY.FIL successfully created.\n");
write(handle, buf, strlen(buf));
close(handle);
}
return 0;
}
º¯ÊýÃû: creattemp
¹¦ ÄÜ: ´´½¨Ò»¸öÐÂÎļþ»òÖØдһ¸öÒÑ´æÔÚµÄÎļþ
ÓÃ ·¨: int creattemp(const char *filename, int attrib);
³ÌÐòÀý:
#include ;
#include ;
#include ;
int main(void)
{
int handle;
char pathname[128];
strcpy(pathname, "\\");
/* create a unique file in the root directory */
handle = creattemp(pathname, 0);
printf("%s was the unique file created.\n", pathname);
close(handle);
return 0;
}
º¯ÊýÃû: cscanf
¹¦ ÄÜ: ´Ó¿ØÖÆִ̨Ðиñʽ»¯ÊäÈë
ÓÃ ·¨: int cscanf(char *format[,argument, ...]);
³ÌÐòÀý:
#include ;
int main(void)
{
char string[80];
/* clear the screen */
clrscr();
/* Prompt the user for input */
cprintf("Enter a string with no spaces:");
/* read the input */
cscanf("%s", string);
/* display what was read */
cprintf("\r\nThe string entered is: %s", string);
return 0;
}
º¯ÊýÃû: ctime
¹¦ ÄÜ: °ÑÈÕÆÚºÍʱ¼äת»»Îª×Ö·û´®
ÓÃ ·¨: char *ctime(const time_t *time);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
time_t t;
time(&t);
printf("Today's date and time: %s\n", ctime(&t));
return 0;
}
º¯ÊýÃû: ctrlbrk
¹¦ ÄÜ: ÉèÖÃCtrl-Break´¦Àí³ÌÐò
ÓÃ ·¨: void ctrlbrk(*fptr)(void);
³ÌÐòÀý:
#include ;
#include ;
#define ABORT 0
int c_break(void)
{
printf("Control-Break pressed. Program aborting ...\n");
return (ABORT);
}
int main(void)
{
ctrlbrk(c_break);
for(;;)
{
printf("Looping... Press ; to quit:\n");
}
return 0;
}
º¯ÊýÃû: delay
¹¦ ÄÜ: ½«³ÌÐòµÄÖ´ÐÐÔÝÍ£Ò»¶Îʱ¼ä(ºÁÃë)
ÓÃ ·¨: void delay(unsigned milliseconds);
³ÌÐòÀý:
/* Emits a 440-Hz tone for 500 milliseconds */
#include ;
int main(void)
{
sound(440);
delay(500);
nosound();
return 0;
}
º¯ÊýÃû: delline
¹¦ ÄÜ: ÔÚÎı¾´°¿ÚÖÐɾȥһÐÐ
ÓÃ ·¨: void delline(void);
³ÌÐòÀý:
#include ;
int main(void)
{
clrscr();
cprintf("The function DELLINE deletes \
the line containing the\r\n");
cprintf("cursor and moves all lines \
below it one line up.\r\n");
cprintf("DELLINE operates within the \
currently active text\r\n");
cprintf("window. Press any key to \
continue . . .");
gotoxy(1,2); /* Move the cursor to the
second line and first column */
getch();
delline();
getch();
return 0;
}
º¯ÊýÃû: detectgraph
¹¦ ÄÜ: ͨ¹ý¼ì²âÓ²¼þÈ·¶¨Í¼ÐÎÇý¶¯³ÌÐòºÍģʽ
ÓÃ ·¨: void far detectgraph(int far *graphdriver, int far *graphmode);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
/* names of the various cards supported */
char *dname[] = { "requests detection",
"a CGA",
"an MCGA",
"an EGA",
"a 64K EGA",
"a monochrome EGA",
"an IBM 8514",
"a Hercules monochrome",
"an AT&T 6300 PC",
"a VGA",
"an IBM 3270 PC"
};
int main(void)
{
/* returns detected hardware info. */
int gdriver, gmode, errorcode;
/* detect graphics hardware available */
detectgraph(&gdriver, &gmode);
/* read result of detectgraph call */
errorcode = graphresult();
if (errorcode != grOk) /* an error
occurred */
{
printf("Graphics error: %s\n", \
grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error
code */
}
/* display the information detected */
clrscr();
printf("You have %s video display \
card.\n", dname[gdriver]);
printf("Press any key to halt:");
getch();
return 0;
}
º¯ÊýÃû: difftime
¹¦ ÄÜ: ¼ÆËãÁ½¸öʱ¿ÌÖ®¼äµÄʱ¼ä²î
ÓÃ ·¨: double difftime(time_t time2, time_t time1);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
time_t first, second;
clrscr();
first = time(NULL); /* Gets system
time */
delay(2000); /* Waits 2 secs */
second = time(NULL); /* Gets system time
again */
printf("The difference is: %f \
seconds\n",difftime(second,first));
getch();
return 0;
}
º¯ÊýÃû: disable
¹¦ ÄÜ: ÆÁ±ÎÖжÏ
ÓÃ ·¨: void disable(void);
³ÌÐòÀý:
/***NOTE: This is an interrupt service
routine. You cannot compile this program
with Test Stack Overflow turned on and
get an executable file that operates
correctly. */
#include ;
#include ;
#include ;
#define INTR 0X1C /* The clock tick
interrupt */
void interrupt ( *oldhandler)(void);
int count=0;
void interrupt handler(void)
{
/* disable interrupts during the handling of
the interrupt */
disable();
/* increase the global counter */
count++;
/* reenable interrupts at the end of the
handler */
enable();
/* call the old routine */
oldhandler();
}
int main(void)
{
/* save the old interrupt vector */
oldhandler = getvect(INTR);
/* install the new interrupt handler */
setvect(INTR, handler);
/* loop until the counter exceeds 20 */
while (count < 20)
printf("count is %d\n",count);
/* reset the old interrupt handler */
setvect(INTR, oldhandler);
return 0;
}
º¯ÊýÃû: div
¹¦ ÄÜ: ½«Á½¸öÕûÊýÏà³ý, ·µ»ØÉ̺ÍÓàÊý
ÓÃ ·¨: div_t (int number, int denom);
³ÌÐòÀý:
#include ;
#include ;
div_t x;
int main(void)
{
x = div(10,3);
printf("10 div 3 = %d remainder %d\n", x.quot, x.rem);
return 0;
}
º¯ÊýÃû: dosexterr
¹¦ ÄÜ: »ñÈ¡À©Õ¹DOS´íÎóÐÅÏ¢
ÓÃ ·¨: int dosexterr(struct DOSERR *dblkp);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
FILE *fp;
struct DOSERROR info;
fp = fopen("perror.dat","r");
if (!fp) perror("Unable to open file for
reading");
dosexterr(&info);
printf("Extended DOS error \
information:\n");
printf(" Extended error: \
%d\n",info.exterror);
printf(" Class: \
%x\n",info.class);
printf(" Action: \
%x\n",info.action);
printf(" Error Locus: \
%x\n",info.locus);
return 0;
}
º¯ÊýÃû: dostounix
¹¦ ÄÜ: ת»»ÈÕÆÚºÍʱ¼äΪUNIXʱ¼ä¸ñʽ
ÓÃ ·¨: long dostounix(struct date *dateptr, struct time *timeptr);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
time_t t;
struct time d_time;
struct date d_date;
struct tm *local;
getdate(&d_date);
gettime(&d_time);
t = dostounix(&d_date, &d_time);
local = localtime(&t);
printf("Time and Date: %s\n", \
asctime(local));
return 0;
}
º¯ÊýÃû: drawpoly
¹¦ ÄÜ: »­¶à±ßÐÎ
ÓÃ ·¨: void far drawpoly(int numpoints, int far *polypoints);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int maxx, maxy;
/* our polygon array */
int poly[10];
/* initialize graphics and local
variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
/* an error occurred */
{
printf("Graphics error: %s\n", \
grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
/* terminate with an error code */
exit(1);
}
maxx = getmaxx();
maxy = getmaxy();
poly[0] = 20; /* 1st vertext */
poly[1] = maxy / 2;
poly[2] = maxx - 20; /* 2nd */
poly[3] = 20;
poly[4] = maxx - 50; /* 3rd */
poly[5] = maxy - 20;
poly[6] = maxx / 2; /* 4th */
poly[7] = maxy / 2;
/*
drawpoly doesn't automatically close
the polygon, so we close it.
*/
poly[8] = poly[0];
poly[9] = poly[1];
/* draw the polygon */
drawpoly(5, poly);
/* clean up */
getch();
closegraph();
return 0;
}
º¯ÊýÃû: dup
¹¦ ÄÜ: ¸´ÖÆÒ»¸öÎļþ¾ä±ú
ÓÃ ·¨: int dup(int handle);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
void flush(FILE *stream);
int main(void)
{
FILE *fp;
char msg[] = "This is a test";
/* create a file */
fp = fopen("DUMMY.FIL", "w");
/* write some data to the file */
fwrite(msg, strlen(msg), 1, fp);
clrscr();
printf("Press any key to flush \
DUMMY.FIL:");
getch();
/* flush the data to DUMMY.FIL without
closing it */
flush(fp);
printf("\nFile was flushed, Press any \
key to quit:");
getch();
return 0;
}
void flush(FILE *stream)
{
int duphandle;
/* flush TC's internal buffer */
fflush(stream);
/* make a duplicate file handle */
duphandle = dup(fileno(stream));
/* close the duplicate handle to flush the
DOS buffer */
close(duphandle);
}
º¯ÊýÃû: dup2
¹¦ ÄÜ: ¸´ÖÆÎļþ¾ä±ú
ÓÃ ·¨: int dup2(int oldhandle, int newhandle);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
#define STDOUT 1
int nul, oldstdout;
char msg[] = "This is a test";
/* create a file */
nul = open("DUMMY.FIL", O_CREAT | O_RDWR,
S_IREAD | S_IWRITE);
/* create a duplicate handle for standard
output */
oldstdout = dup(STDOUT);
/*
redirect standard output to DUMMY.FIL
by duplicating the file handle onto the
file handle for standard output.
*/
dup2(nul, STDOUT);
/* close the handle for DUMMY.FIL */
close(nul);
/* will be redirected into DUMMY.FIL */
write(STDOUT, msg, strlen(msg));
/* restore original standard output
handle */
dup2(oldstdout, STDOUT);
/* close duplicate handle for STDOUT */
close(oldstdout);
return 0;
}
º¯ÊýÃû: ecvt
¹¦ ÄÜ: °ÑÒ»¸ö¸¡µãÊýת»»Îª×Ö·û´®
ÓÃ ·¨: char ecvt(double value, int ndigit, int *decpt, int *sign);
³ÌÐòÀý:
#include ;
#include ;
#include ;
int main(void)
{
char *string;
double value;
int dec, sign;
int ndig = 10;
clrscr();
value = 9.876;
string = ecvt(value, ndig, &dec, &sign);
printf("string = %s dec = %d \
sign = %d\n", string, dec, sign);
value = -123.45;
ndig= 15;
string = ecvt(value,ndig,&dec,&sign);
printf("string = %s dec = %d sign = %d\n",
string, dec, sign);
value = 0.6789e5; /* scientific
notation */
ndig = 5;
string = ecvt(value,ndig,&dec,&sign);
printf("string = %s dec = %d\
sign = %d\n", string, dec, sign);
return 0;
}
º¯ÊýÃû: ellipse
¹¦ ÄÜ: »­Ò»ÍÖÔ²
ÓÃ ·¨: void far ellipse(int x, int y, int stangle, int endangle,
int xradius, int yradius);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int midx, midy;
int stangle = 0, endangle = 360;
int xradius = 100, yradius = 50;
/* initialize graphics, local variables */
initgraph(&gdriver, &gmode, "");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
/* an error occurred */
{
printf("Graphics error: %s\n",
grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
/* terminate with an error code */
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());
/* draw ellipse */
ellipse(midx, midy, stangle, endangle,
xradius, yradius);
/* clean up */
getch();
closegraph();
return 0;
}
º¯ÊýÃû: enable
¹¦ ÄÜ: ¿ª·ÅÓ²¼þÖжÏ
ÓÃ ·¨: void enable(void);
³ÌÐòÀý:
/* ** NOTE:
This is an interrupt service routine. You can NOT compile this program
with Test Stack Overflow turned on and get an executable file which will
operate correctly.
*/
#include ;
#include ;
#include ;
/* The clock tick interrupt */
#define INTR 0X1C
void interrupt ( *oldhandler)(void);
int count=0;
void interrupt handler(void)
{
/*
disable interrupts during the handling of the interrupt
*/
disable();
/* increase the global counter */
count++;
/*
re enable interrupts at the end of the handler
*/
enable();
/* call the old routine */
oldhandler();
}
int main(void)
{
/* save the old interrupt vector */
oldhandler = getvect(INTR);
/* install the new interrupt handler */
setvect(INTR, handler);
/* loop until the counter exceeds 20 */
while (count < 20)
printf("count is %d\n",count);
/* reset the old interrupt handler */
setvect(INTR, oldhandler);
return 0;
}
º¯ÊýÃû: eof
¹¦ ÄÜ: ¼ì²âÎļþ½áÊø
ÓÃ ·¨: int eof(int *handle);
³ÌÐòÀý:
#include ;
#include ;
#include ;
#include ;
#include ;
int main(void)
{
int handle;
char msg[] = "This is a test";
char ch;
/* create a file */
handle = open("DUMMY.FIL",
O_CREAT | O_RDWR,
S_IREAD | S_IWRITE);
/* write some data to the file */
write(handle, msg, strlen(msg));
/* seek to the beginning of the file */
lseek(handle, 0L, SEEK_SET);
/*
reads chars from the file until hit EOF
*/
do
{
read(handle, &ch, 1);
printf("%c", ch);
} while (!eof(handle));
close(handle);
return 0;
}
º¯ÊýÃû: exec...
¹¦ ÄÜ: ×°Èë²¢ÔËÐÐÆäËü³ÌÐòµÄº¯Êý
ÓÃ ·¨: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL);
int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,
char *envp[]);
int execlp(char *pathname, char *arg0, arg1, .., NULL);
int execple(char *pathname, char *arg0, arg1, ..., NULL,
char *envp[]);
int execv(char *pathname, char *argv[]);
int execve(char *pathname, char *argv[], char *envp[]);
int execvp(char *pathname, char *argv[]);
int execvpe(char *pathname, char *argv[], char *envp[]);
³ÌÐòÀý:
/* execv example */
#include ;
#include ;
#include ;
void main(int argc, char *argv[])
{
int i;
printf("Command line arguments:\n");
for (i=0; iprintf("[%2d] : %s\n", i, argv[i]);
printf("About to exec child with arg1 arg2 ...\n");
execv("CHILD.EXE", argv);
perror("exec error");
exit(1);
}
º¯ÊýÃû: exit
¹¦ ÄÜ: ÖÕÖ¹³ÌÐò
ÓÃ ·¨: void exit(int status);
³ÌÐòÀý:
#include ;
#include ;
#include ;
int main(void)
{
int status;
printf("Enter either 1 or 2\n");
status = getch();
/* Sets DOS errorlevel */
exit(status - '0');
/* Note: this line is never reached */
return 0;
}
º¯ÊýÃû: exp
¹¦ ÄÜ: Ö¸Êýº¯Êý
ÓÃ ·¨: double exp(double x);
³ÌÐòÀý:
#include ;
#include ;
int main(void)
{
double result;
double x = 4.0;
result = exp(x);
printf("'e' raised to the power \
of %lf (e ^ %lf) = %lf\n",
x, x, result);
return 0;
}
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 9 ÌõÆÀÂÛ

  1. honglianqxw123 ÓÚ 2012-02-07 09:06:21·¢±í:

    ×÷ÕßÕæÁ˲»Æð£¬Åå·þ¡£

  2. heimanba ÓÚ 2011-08-02 22:50:59·¢±í:

    Ì«Ç¿´óÁË¡£¡£¡£ÓÐÊÕ»ñ°¡

  3. feiyuezxb510 ÓÚ 2011-05-31 09:45:58·¢±í:

    ¡£¡£¡£

  4. linjunqian ÓÚ 2011-05-28 19:48:41·¢±í:

    good

  5. pigmike ÓÚ 2010-11-03 16:51:13·¢±í:

    ²»´í....ÓÐÊÕ»ñ¹þ¹þ

  6. hfh08 ÓÚ 2006-08-21 15:58:51·¢±í:

    º¯ÊýÃû: open
    ¹¦ ÄÜ: ´ò¿ªÒ»¸öÎļþÓÃÓÚ¶Á»òд
    ÓÃ ·¨: int open(char *pathname, int access[, int permiss]);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    int handle;
    char msg[] = "Hello world";
    if ((handle = open("TEST.$$$", O_CREAT | O_TEXT)) == -1)
    {
    perror("Error:");
    return 1;
    }
    write(handle, msg, strlen(msg));
    close(handle);
    return 0;
    }


    º¯ÊýÃû: outport
    ¹¦ ÄÜ: Êä³öÕûÊýµ½Ó²¼þ¶Ë¿ÚÖÐ
    ÓÃ ·¨: void outport(int port, int value);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    int value = 64;
    int port = 0;
    outportb(port, value);
    printf("Value %d sent to port number %d\n", value, port);
    return 0;
    }


    º¯ÊýÃû: outportb
    ¹¦ ÄÜ: Êä³ö×Ö½Úµ½Ó²¼þ¶Ë¿ÚÖÐ
    ÓÃ ·¨: void outportb(int port, char byte);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    int value = 64;
    int port = 0;
    outportb(port, value);
    printf("Value %d sent to port number %d\n", value, port);
    return 0;
    }


    º¯ÊýÃû: outtext
    ¹¦ ÄÜ: ÔÚÊÓÇøÏÔʾһ¸ö×Ö·û´®
    ÓÃ ·¨: void far outtext(char far *textstring);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int midx, midy;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* move the C.P. to the center of the screen */
    moveto(midx, midy);
    /* output text starting at the C.P. */
    outtext("This ");
    outtext("is ");
    outtext("a ");
    outtext("test.");
    /* clean up */
    getch();
    closegraph();
    return 0;
    }


    º¯ÊýÃû: outtextxy
    ¹¦ ÄÜ: ÔÚÖ¸¶¨Î»ÖÃÏÔʾһ×Ö·û´®
    ÓÃ ·¨: void far outtextxy(int x, int y, char *textstring);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int midx, midy;
    /* initialize graphics and local variables */
    initgraph( &gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* output text at the center of the screen*/
    /* Note: the C.P. doesn't get changed.*/
    outtextxy(midx, midy, "This is a test.");
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: parsfnm
    ¹¦ ÄÜ: ·ÖÎöÎļþÃû
    ÓÃ ·¨: char *parsfnm (char *cmdline, struct fcb *fcbptr, int option);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char line[80];
    struct fcb blk;
    /* get file name */
    printf("Enter drive and file name (no path - ie. a:file.dat)\n");
    gets(line);
    /* put file name in fcb */
    if (parsfnm(line, &blk, 1) == NULL)
    printf("Error in parsfm call\n");
    else
    printf("Drive #%d Name: %11s\n", blk.fcb_drive, blk.fcb_name);
    return 0;
    }


    º¯ÊýÃû: peek
    ¹¦ ÄÜ: ¼ì²é´æ´¢µ¥Ôª
    ÓÃ ·¨: int peek(int segment, unsigned offset);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    int value = 0;
    printf("The current status of your keyboard is:\n");
    value = peek(0x0040, 0x0017);
    if (value & 1)
    printf("Right shift on\n");
    else
    printf("Right shift off\n");
    if (value & 2)
    printf("Left shift on\n");
    else
    printf("Left shift off\n");
    if (value & 4)
    printf("Control key on\n");
    else
    printf("Control key off\n");
    if (value & 8)
    printf("Alt key on\n");
    else
    printf("Alt key off\n");
    if (value & 16)
    printf("Scroll lock on\n");
    else
    printf("Scroll lock off\n");
    if (value & 32)
    printf("Num lock on\n");
    else
    printf("Num lock off\n");
    if (value & 64)
    printf("Caps lock on\n");
    else
    printf("Caps lock off\n");
    return 0;
    }


    º¯ÊýÃû: peekb
    ¹¦ ÄÜ: ¼ì²é´æ´¢µ¥Ôª
    ÓÃ ·¨: char peekb (int segment, unsigned offset);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    int value = 0;
    printf("The current status of your keyboard is:\n");
    value = peekb(0x0040, 0x0017);
    if (value & 1)
    printf("Right shift on\n");
    else
    printf("Right shift off\n");
    if (value & 2)
    printf("Left shift on\n");
    else
    printf("Left shift off\n");
    if (value & 4)
    printf("Control key on\n");
    else
    printf("Control key off\n");
    if (value & 8)
    printf("Alt key on\n");
    else
    printf("Alt key off\n");
    if (value & 16)
    printf("Scroll lock on\n");
    else
    printf("Scroll lock off\n");
    if (value & 32)
    printf("Num lock on\n");
    else
    printf("Num lock off\n");
    if (value & 64)
    printf("Caps lock on\n");
    else
    printf("Caps lock off\n");
    return 0;
    }


    º¯ÊýÃû: perror
    ¹¦ ÄÜ: ϵͳ´íÎóÐÅÏ¢
    ÓÃ ·¨: void perror(char *string);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    FILE *fp;
    fp = fopen("perror.dat", "r");
    if (!fp)
    perror("Unable to open file for reading");
    return 0;
    }


    º¯ÊýÃû: pieslice
    ¹¦ ÄÜ: »æÖƲ¢Ìî³äÒ»¸öÉÈÐÎ
    ÓÃ ·¨: void far pieslice(int x, int stanle, int endangle, int radius);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int midx, midy;
    int stangle = 45, endangle = 135, radius = 100;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* set fill style and draw a pie slice */
    setfillstyle(EMPTY_FILL, getmaxcolor());
    pieslice(midx, midy, stangle, endangle, radius);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }


    º¯ÊýÃû: poke
    ¹¦ ÄÜ: ´æÖµµ½Ò»¸ö¸ø¶¨´æ´¢µ¥Ôª
    ÓÃ ·¨: void poke(int segment, int offset, int value);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    clrscr();
    cprintf("Make sure the scroll lock key is off and press any key\r\n");
    getch();
    poke(0x0000,0x0417,16);
    cprintf("The scroll lock is now on\r\n");
    return 0;
    }


    º¯ÊýÃû: pokeb
    ¹¦ ÄÜ: ´æÖµµ½Ò»¸ö¸ø¶¨´æ´¢µ¥Ôª
    ÓÃ ·¨: void pokeb(int segment, int offset, char value);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    clrscr();
    cprintf("Make sure the scroll lock key is off and press any key\r\n");
    getch();
    pokeb(0x0000,0x0417,16);
    cprintf("The scroll lock is now on\r\n");
    return 0;
    }


    º¯ÊýÃû: poly
    ¹¦ ÄÜ: ¸ù¾Ý²ÎÊý²úÉúÒ»¸ö¶àÏîʽ
    ÓÃ ·¨: double poly(double x, int n, double c[]);
    ³ÌÐòÀý:
    #include ;
    #include ;
    /* polynomial: x**3 - 2x**2 + 5x - 1 */
    int main(void)
    {
    double array[] = { -1.0, 5.0, -2.0, 1.0 };
    double result;
    result = poly(2.0, 3, array);
    printf("The polynomial: x**3 - 2.0x**2 + 5x - 1 at 2.0 is %lf\n",
    result);
    return 0;
    }


    º¯ÊýÃû: pow
    ¹¦ ÄÜ: Ö¸Êýº¯Êý(xµÄy´Î·½)
    ÓÃ ·¨: double pow(double x, double y);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    double x = 2.0, y = 3.0;
    printf("%lf raised to %lf is %lf\n", x, y, pow(x, y));
    return 0;
    }

    º¯ÊýÃû: pow10
    ¹¦ ÄÜ: Ö¸Êýº¯Êý(10µÄp´Î·½)
    ÓÃ ·¨: double pow10(int p);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    double p = 3.0;
    printf("Ten raised to %lf is %lf\n", p, pow10(p));
    return 0;
    }


    º¯ÊýÃû: printf
    ¹¦ ÄÜ: ²úÉú¸ñʽ»¯Êä³öµÄº¯Êý
    ÓÃ ·¨: int printf(char *format...);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #define I 555
    #define R 5.5
    int main(void)
    {
    int i,j,k,l;
    char buf[7];
    char *prefix = buf;
    char tp[20];
    printf("prefix 6d 6o 8x 10.2e "
    "10.2f\n");
    strcpy(prefix,"%");
    for (i = 0; i < 2; i++)
    {
    for (j = 0; j < 2; j++)
    for (k = 0; k < 2; k++)
    for (l = 0; l < 2; l++)
    {
    if (i==0) strcat(prefix,"-");
    if (j==0) strcat(prefix,"+");
    if (k==0) strcat(prefix,"#");
    if (l==0) strcat(prefix,"0");
    printf("%5s |",prefix);
    strcpy(tp,prefix);
    strcat(tp,"6d |");
    printf(tp,I);
    strcpy(tp,"");
    strcpy(tp,prefix);
    strcat(tp,"6o |");
    printf(tp,I);
    strcpy(tp,"");
    strcpy(tp,prefix);
    strcat(tp,"8x |");
    printf(tp,I);
    strcpy(tp,"");
    strcpy(tp,prefix);
    strcat(tp,"10.2e |");
    printf(tp,R);
    strcpy(tp,prefix);
    strcat(tp,"10.2f |");
    printf(tp,R);
    printf(" \n");
    strcpy(prefix,"%");
    }
    }
    return 0;
    }


    º¯ÊýÃû: putc
    ¹¦ ÄÜ: Êä³öÒ»×Ö·ûµ½Ö¸¶¨Á÷ÖÐ
    ÓÃ ·¨: int putc(int ch, FILE *stream);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    char msg[] = "Hello world\n";
    int i = 0;
    while (msg[i])
    putc(msg[i++], stdout);
    return 0;
    }


    º¯ÊýÃû: putch
    ¹¦ ÄÜ: Êä³ö×Ö·ûµ½¿ØÖÆ̨
    ÓÃ ·¨: int putch(int ch);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char ch = 0;
    printf("Input a string:");
    while ((ch != '\r'))
    {
    ch = getch();
    putch(ch);
    }
    return 0;
    }


    º¯ÊýÃû: putchar
    ¹¦ ÄÜ: ÔÚstdoutÉÏÊä³ö×Ö·û
    ÓÃ ·¨: int putchar(int ch);
    ³ÌÐòÀý:
    #include ;
    /* define some box-drawing characters */
    #define LEFT_TOP 0xDA
    #define RIGHT_TOP 0xBF
    #define HORIZ 0xC4
    #define VERT 0xB3
    #define LEFT_BOT 0xC0
    #define RIGHT_BOT 0xD9
    int main(void)
    {
    char i, j;
    /* draw the top of the box */
    putchar(LEFT_TOP);
    for (i=0; i<10; i++)
    putchar(HORIZ);
    putchar(RIGHT_TOP);
    putchar('\n');
    /* draw the middle */
    for (i=0; i<4; i++)
    {
    putchar(VERT);
    for (j=0; j<10; j++)
    putchar(' ');
    putchar(VERT);
    putchar('\n');
    }
    /* draw the bottom */
    putchar(LEFT_BOT);
    for (i=0; i<10; i++)
    putchar(HORIZ);
    putchar(RIGHT_BOT);
    putchar('\n');
    return 0;
    }


    º¯ÊýÃû: putenv
    ¹¦ ÄÜ: °Ñ×Ö·û´®¼Óµ½µ±Ç°»·¾³ÖÐ
    ÓÃ ·¨: int putenv(char *envvar);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char *path, *ptr;
    int i = 0;
    /* get the current path environment */
    ptr = getenv("PATH");
    /* set up new path */
    path = malloc(strlen(ptr)+15);
    strcpy(path,"PATH=");
    strcat(path,ptr);
    strcat(path,";c:\\temp");
    /* replace the current path and display current environment */
    putenv(path);
    while (environ[i])
    printf("%s\n",environ[i++]);
    return 0;
    }


    º¯ÊýÃû: putimage
    ¹¦ ÄÜ: ÔÚÆÁÄ»ÉÏÊä³öÒ»¸öλͼ
    ÓÃ ·¨: void far putimage(int x, int y, void far *bitmap, int op);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #define ARROW_SIZE 10
    void draw_arrow(int x, int y);
    int main(void)
    {
    /* request autodetection */
    int gdriver = DETECT, gmode, errorcode;
    void *arrow;
    int x, y, maxx;
    unsigned int size;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    maxx = getmaxx();
    x = 0;
    y = getmaxy() / 2;
    /* draw the image to be grabbed */
    draw_arrow(x, y);
    /* calculate the size of the image */
    size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE);
    /* allocate memory to hold the image */
    arrow = malloc(size);
    /* grab the image */
    getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow);
    /* repeat until a key is pressed */
    while (!kbhit())
    {
    /* erase old image */
    putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
    x += ARROW_SIZE;
    if (x >;= maxx)
    x = 0;
    /* plot new image */
    putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
    }
    /* clean up */
    free(arrow);
    closegraph();
    return 0;
    }
    void draw_arrow(int x, int y)
    {
    /* draw an arrow on the screen */
    moveto(x, y);
    linerel(4*ARROW_SIZE, 0);
    linerel(-2*ARROW_SIZE, -1*ARROW_SIZE);
    linerel(0, 2*ARROW_SIZE);
    linerel(2*ARROW_SIZE, -1*ARROW_SIZE);
    }


    º¯ÊýÃû: putpixel
    ¹¦ ÄÜ: ÔÚÖ¸¶¨Î»Öû­Ò»ÏñËØ
    ÓÃ ·¨: void far putpixel (int x, int y, int pixelcolor);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #include ;
    #define PIXEL_COUNT 1000
    #define DELAY_TIME 100 /* in milliseconds */
    int main(void)
    {
    /* request autodetection */
    int gdriver = DETECT, gmode, errorcode;
    int i, x, y, color, maxx, maxy, maxcolor, seed;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    maxx = getmaxx() + 1;
    maxy = getmaxy() + 1;
    maxcolor = getmaxcolor() + 1;
    while (!kbhit())
    {
    /* seed the random number generator */
    seed = random(32767);
    srand(seed);
    for (i=0; i {
    x = random(maxx);
    y = random(maxy);
    color = random(maxcolor);
    putpixel(x, y, color);
    }
    delay(DELAY_TIME);
    srand(seed);
    for (i=0; i {
    x = random(maxx);
    y = random(maxy);
    color = random(maxcolor);
    if (color == getpixel(x, y))
    putpixel(x, y, 0);
    }
    }
    /* clean up */
    getch();
    closegraph();
    return 0;
    }


    º¯ÊýÃû: puts
    ¹¦ ÄÜ: ËÍÒ»×Ö·û´®µ½Á÷ÖÐ
    ÓÃ ·¨: int puts(char *string);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    char string[] = "This is an example output string\n";
    puts(string);
    return 0;
    }


    º¯ÊýÃû: puttext
    ¹¦ ÄÜ: ½«Îı¾´Ó´æ´¢Çø¿½±´µ½ÆÁÄ»
    ÓÃ ·¨: int puttext(int left, int top, int right, int bottom, void *source);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    char buffer[512];
    /* put some text to the console */
    clrscr();
    gotoxy(20, 12);
    cprintf("This is a test. Press any key to continue ...");
    getch();
    /* grab screen contents */
    gettext(20, 12, 36, 21,buffer);
    clrscr();
    /* put selected characters back to the screen */
    gotoxy(20, 12);
    puttext(20, 12, 36, 21, buffer);
    getch();
    return 0;
    }


    º¯ÊýÃû: putw
    ¹¦ ÄÜ: °ÑÒ»×Ö·û»ò×ÖË͵½Á÷ÖÐ
    ÓÃ ·¨: int putw(int w, FILE *stream);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #define FNAME "test.$$$"
    int main(void)
    {
    FILE *fp;
    int word;
    /* place the word in a file */
    fp = fopen(FNAME, "wb");
    if (fp == NULL)
    {
    printf("Error opening file %s\n", FNAME);
    exit(1);
    }
    word = 94;
    putw(word,fp);
    if (ferror(fp))
    printf("Error writing to file\n");
    else
    printf("Successful write\n");
    fclose(fp);
    /* reopen the file */
    fp = fopen(FNAME, "rb");
    if (fp == NULL)
    {
    printf("Error opening file %s\n", FNAME);
    exit(1);
    }
    /* extract the word */
    word = getw(fp);
    if (ferror(fp))
    printf("Error reading file\n");
    else
    printf("Successful read: word = %d\n", word);
    /* clean up */
    fclose(fp);
    unlink(FNAME);
    return 0;
    }
    º¯ÊýÃû: qsort
    ¹¦ ÄÜ: ʹÓÿìËÙÅÅÐòÀý³Ì½øÐÐÅÅÐò
    ÓÃ ·¨: void qsort(void *base, int nelem, int width, int (*fcmp)());
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int sort_function( const void *a, const void *b);
    char list[5][4] = { "cat", "car", "cab", "cap", "can" };

    int main(void)
    {
    int x;
    qsort((void *)list, 5, sizeof(list[0]), sort_function);
    for (x = 0; x < 5; x++)
    printf("%s\n", list[x]);
    return 0;
    }
    int sort_function( const void *a, const void *b)
    {
    return( strcmp(a,b) );
    }
    º¯ÊýÃû: raise
    ¹¦ ÄÜ: ÏòÕýÔÚÖ´ÐеijÌÐò·¢ËÍÒ»¸öÐźÅ
    ÓÃ ·¨: int raise(int sig);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    int a, b;
    a = 10;
    b = 0;
    if (b == 0)
    /* preempt divide by zero error */
    raise(SIGFPE);
    a = a / b;
    return 0;
    }


    º¯ÊýÃû: rand
    ¹¦ ÄÜ: Ëæ»úÊý·¢ÉúÆ÷
    ÓÃ ·¨: void rand(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    int i;
    printf("Ten random numbers from 0 to 99\n\n");
    for(i=0; i<10; i++)
    printf("%d\n", rand() % 100);
    return 0;
    }


    º¯ÊýÃû: randbrd
    ¹¦ ÄÜ: Ëæ»ú¿é¶Á
    ÓÃ ·¨: int randbrd(struct fcb *fcbptr, int reccnt);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char far *save_dta;
    char line[80], buffer[256];
    struct fcb blk;
    int i, result;
    /* get user input file name for dta */
    printf("Enter drive and file name (no path - i.e. a:file.dat)\n");
    gets(line);
    /* put file name in fcb */
    if (!parsfnm(line, &blk, 1))
    {
    printf("Error in call to parsfnm\n");
    exit(1);
    }
    printf("Drive #%d File: %s\n\n", blk.fcb_drive, blk.fcb_name);
    /* open file with DOS FCB open file */
    bdosptr(0x0F, &blk, 0);
    /* save old dta, and set new one */
    save_dta = getdta();
    setdta(buffer);
    /* set up info for the new dta */
    blk.fcb_recsize = 128;
    blk.fcb_random = 0L;
    result = randbrd(&blk, 1);
    /* check results from randbrd */
    if (!result)
    printf("Read OK\n\n");
    else
    {
    perror("Error during read");
    exit(1);
    }
    /* read in data from the new dta */
    printf("The first 128 characters are:\n");
    for (i=0; i<128; i++)
    putchar(buffer[i]);
    /* restore previous dta */
    setdta(save_dta);
    return 0;
    }

    º¯ÊýÃû: randbwr
    ¹¦ ÄÜ: Ëæ»ú¿éд
    ÓÃ ·¨: int randbwr(struct fcp *fcbptr, int reccnt);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char far *save_dta;
    char line[80];
    char buffer[256] = "RANDBWR test!";
    struct fcb blk;
    int result;
    /* get new file name from user */
    printf("Enter a file name to create (no path - ie. a:file.dat\n");
    gets(line);
    /* parse the new file name to the dta */
    parsfnm(line,&blk,1);
    printf("Drive #%d File: %s\n", blk.fcb_drive, blk.fcb_name);
    /* request DOS services to create file */
    if (bdosptr(0x16, &blk, 0) == -1)
    {
    perror("Error creating file");
    exit(1);
    }
    /* save old dta and set new dta */
    save_dta = getdta();
    setdta(buffer);
    /* write new records */
    blk.fcb_recsize = 256;
    blk.fcb_random = 0L;
    result = randbwr(&blk, 1);
    if (!result)
    printf("Write OK\n");
    else
    {
    perror("Disk error");
    exit(1);
    }
    /* request DOS services to close the file */
    if (bdosptr(0x10, &blk, 0) == -1)
    {
    perror("Error closing file");
    exit(1);
    }
    /* reset the old dta */
    setdta(save_dta);
    return 0;
    }


    º¯ÊýÃû: random
    ¹¦ ÄÜ: Ëæ»úÊý·¢ÉúÆ÷
    ÓÃ ·¨: int random(int num);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    /* prints a random number in the range 0 to 99 */
    int main(void)
    {
    randomize();
    printf("Random number in the 0-99 range: %d\n", random (100));
    return 0;
    }


    º¯ÊýÃû: randomize
    ¹¦ ÄÜ: ³õʼ»¯Ëæ»úÊý·¢ÉúÆ÷
    ÓÃ ·¨: void randomize(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    int i;
    randomize();
    printf("Ten random numbers from 0 to 99\n\n");
    for(i=0; i<10; i++)
    printf("%d\n", rand() % 100);
    return 0;
    }


    º¯ÊýÃû: read
    ¹¦ ÄÜ: ´ÓÎļþÖжÁ
    ÓÃ ·¨: int read(int handle, void *buf, int nbyte);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    void *buf;
    int handle, bytes;
    buf = malloc(10);
    /*
    Looks for a file in the current directory named TEST.$$$ and attempts
    to read 10 bytes from it. To use this example you should create the
    file TEST.$$$
    */
    if ((handle =
    open("TEST.$$$", O_RDONLY | O_BINARY, S_IWRITE | S_IREAD)) == -1)
    {
    printf("Error Opening File\n");
    exit(1);
    }
    if ((bytes = read(handle, buf, 10)) == -1) {
    printf("Read Failed.\n");
    exit(1);
    }
    else {
    printf("Read: %d bytes read.\n", bytes);
    }
    return 0;
    }


    º¯ÊýÃû: realloc
    ¹¦ ÄÜ: ÖØзÖÅäÖ÷´æ
    ÓÃ ·¨: void *realloc(void *ptr, unsigned newsize);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char *str;
    /* allocate memory for string */
    str = malloc(10);
    /* copy "Hello" into string */
    strcpy(str, "Hello");
    printf("String is %s\n Address is %p\n", str, str);
    str = realloc(str, 20);
    printf("String is %s\n New address is %p\n", str, str);
    /* free memory */
    free(str);
    return 0;
    }


    º¯ÊýÃû: rectangle
    ¹¦ ÄÜ: »­Ò»¸ö¾ØÐÎ
    ÓÃ ·¨: void far rectangle(int left, int top, int right, int bottom);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int left, top, right, bottom;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    left = getmaxx() / 2 - 50;
    top = getmaxy() / 2 - 50;
    right = getmaxx() / 2 + 50;
    bottom = getmaxy() / 2 + 50;
    /* draw a rectangle */
    rectangle(left,top,right,bottom);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }


    º¯ÊýÃû: registerbgidriver
    ¹¦ ÄÜ: µÇ¼ÒÑÁ¬½Ó½øÀ´µÄͼÐÎÇý¶¯³ÌÐò´úÂë
    ÓÃ ·¨: int registerbgidriver(void(*driver)(void));
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    /* register a driver that was added into graphics.lib */
    errorcode = registerbgidriver(EGAVGA_driver);
    /* report any registration errors */
    if (errorcode < 0)
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    /* draw a line */
    line(0, 0, getmaxx(), getmaxy());
    /* clean up */
    getch();
    closegraph();
    return 0;
    }


    º¯ÊýÃû: remove
    ¹¦ ÄÜ: ɾ³ýÒ»¸öÎļþ
    ÓÃ ·¨: int remove(char *filename);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    char file[80];
    /* prompt for file name to delete */
    printf("File to delete: ");
    gets(file);
    /* delete the file */
    if (remove(file) == 0)
    printf("Removed %s.\n",file);
    else
    perror("remove");
    return 0;
    }


    º¯ÊýÃû: rename
    ¹¦ ÄÜ: ÖØÃüÃûÎļþ
    ÓÃ ·¨: int rename(char *oldname, char *newname);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    char oldname[80], newname[80];
    /* prompt for file to rename and new name */
    printf("File to rename: ");
    gets(oldname);
    printf("New name: ");
    gets(newname);
    /* Rename the file */
    if (rename(oldname, newname) == 0)
    printf("Renamed %s to %s.\n", oldname, newname);
    else
    perror("rename");
    return 0;
    }


    º¯ÊýÃû: restorecrtmode
    ¹¦ ÄÜ: ½«ÆÁĻģʽ»Ö¸´ÎªÏÈÇ°µÄimitgraphÉèÖÃ
    ÓÃ ·¨: void far restorecrtmode(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int x, y;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    x = getmaxx() / 2;
    y = getmaxy() / 2;
    /* output a message */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(x, y, "Press any key to exit graphics:");
    getch();
    /* restore system to text mode */
    restorecrtmode();
    printf("We're now in text mode.\n");
    printf("Press any key to return to graphics mode:");
    getch();
    /* return to graphics mode */
    setgraphmode(getgraphmode());
    /* output a message */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(x, y, "We're back in graphics mode.");
    outtextxy(x, y+textheight("W"), "Press any key to halt:");
    /* clean up */
    getch();
    closegraph();
    return 0;
    }


    º¯ÊýÃû: rewind
    ¹¦ ÄÜ: ½«ÎļþÖ¸ÕëÖØÐÂÖ¸ÏòÒ»¸öÁ÷µÄ¿ªÍ·
    ÓÃ ·¨: int rewind(FILE *stream);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    FILE *fp;
    char *fname = "TXXXXXX", *newname, first;
    newname = mktemp(fname);
    fp = fopen(newname,"w+");
    fprintf(fp,"abcdefghijklmnopqrstuvwxyz");
    rewind(fp);
    fscanf(fp,"%c",&first);
    printf("The first character is: %c\n",first);
    fclose(fp);
    remove(newname);
    return 0;
    }


    º¯ÊýÃû: rmdir
    ¹¦ ÄÜ: ɾ³ýDOSÎļþĿ¼
    ÓÃ ·¨: int rmdir(char *stream);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #define DIRNAME "testdir.$$$"
    int main(void)
    {
    int stat;
    stat = mkdir(DIRNAME);
    if (!stat)
    printf("Directory created\n");
    else
    {
    printf("Unable to create directory\n");
    exit(1);
    }
    getch();
    system("dir/p");
    getch();
    stat = rmdir(DIRNAME);
    if (!stat)
    printf("\nDirectory deleted\n");
    else
    {
    perror("\nUnable to delete directory\n");
    exit(1);
    }
    return 0;
    }
    º¯ÊýÃû: sbrk
    ¹¦ ÄÜ: ¸Ä±äÊý¾Ý¶Î¿Õ¼äλÖÃ
    ÓÃ ·¨: char *sbrk(int incr);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    printf("Changing allocation with sbrk()\n");
    printf("Before sbrk() call: %lu bytes free\n",
    (unsigned long) coreleft());
    sbrk(1000);
    printf(" After sbrk() call: %lu bytes free\n",
    (unsigned long) coreleft());
    return 0;
    }


    º¯ÊýÃû: scanf
    ¹¦ ÄÜ: Ö´Ðиñʽ»¯ÊäÈë
    ÓÃ ·¨: int scanf(char *format[,argument,...]);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char label[20];
    char name[20];
    int entries = 0;
    int loop, age;
    double salary;
    struct Entry_struct
    {
    char name[20];
    int age;
    float salary;
    } entry[20];
    /* Input a label as a string of characters restricting to 20 characters */
    printf("\n\nPlease enter a label for the chart: ");
    scanf("%20s", label);
    fflush(stdin); /* flush the input stream in case of bad input */
    /* Input number of entries as an integer */
    printf("How many entries will there be? (less than 20) ");
    scanf("%d", &entries);
    fflush(stdin); /* flush the input stream in case of bad input */
    /* input a name restricting input to only letters upper or lower case */
    for (loop=0;loop {
    printf("Entry %d\n", loop);
    printf(" Name : ");
    scanf("%[A-Za-z]", entry[loop].name);
    fflush(stdin); /* flush the input stream in case of bad input */
    /* input an age as an integer */
    printf(" Age : ");
    scanf("%d", &entry[loop].age);
    fflush(stdin); /* flush the input stream in case of bad input */
    /* input a salary as a float */
    printf(" Salary : ");
    scanf("%f", &entry[loop].salary);
    fflush(stdin); /* flush the input stream in case of bad input */
    }
    /* Input a name, age and salary as a string, integer, and double */
    printf("\nPlease enter your name, age and salary\n");
    scanf("%20s %d %lf", name, &age, &salary);

    /* Print out the data that was input */
    printf("\n\nTable %s\n",label);
    printf("Compiled by %s age %d $%15.2lf\n", name, age, salary);
    printf("-----------------------------------------------------\n");
    for (loop=0;loop printf("%4d | %-20s | %5d | %15.2lf\n",
    loop + 1,
    entry[loop].name,
    entry[loop].age,
    entry[loop].salary);
    printf("-----------------------------------------------------\n");
    return 0;
    }


    º¯ÊýÃû: searchpath
    ¹¦ ÄÜ: ËÑË÷DOS·¾¶
    ÓÃ ·¨: char *searchpath(char *filename);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char *p;
    /* Looks for TLINK and returns a pointer
    to the path */
    p = searchpath("TLINK.EXE");
    printf("Search for TLINK.EXE : %s\n", p);
    /* Looks for non-existent file */
    p = searchpath("NOTEXIST.FIL");
    printf("Search for NOTEXIST.FIL : %s\n", p);
    return 0;
    }


    º¯ÊýÃû: sector
    ¹¦ ÄÜ: »­²¢Ìî³äÍÖÔ²ÉÈÇø
    ÓÃ ·¨: void far sector(int x, int y, int stangle, int endangle);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int midx, midy, i;
    int stangle = 45, endangle = 135;
    int xrad = 100, yrad = 50;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* loop through the fill patterns */
    for (i=EMPTY_FILL; i {
    /* set the fill style */
    setfillstyle(i, getmaxcolor());
    /* draw the sector slice */
    sector(midx, midy, stangle, endangle, xrad, yrad);
    getch();
    }
    /* clean up */
    closegraph();
    return 0;
    }

    º¯ÊýÃû: segread
    ¹¦ ÄÜ: ¶Á¶Î¼Ä´æÆ÷Öµ
    ÓÃ ·¨: void segread(struct SREGS *segtbl);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    struct SREGS segs;
    segread(&segs);
    printf("Current segment register settings\n\n");
    printf("CS: %X DS: %X\n", segs.cs, segs.ds);
    printf("ES: %X SS: %X\n", segs.es, segs.ss);
    return 0;
    }


    º¯ÊýÃû: setactivepage
    ¹¦ ÄÜ: ÉèÖÃͼÐÎÊä³ö»î¶¯Ò³
    ÓÃ ·¨: void far setactivepage(int pagenum);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* select a driver and mode that supports */
    /* multiple pages. */
    int gdriver = EGA, gmode = EGAHI, errorcode;
    int x, y, ht;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    x = getmaxx() / 2;
    y = getmaxy() / 2;
    ht = textheight("W");
    /* select the off screen page for drawing */
    setactivepage(1);
    /* draw a line on page #1 */
    line(0, 0, getmaxx(), getmaxy());
    /* output a message on page #1 */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(x, y, "This is page #1:");
    outtextxy(x, y+ht, "Press any key to halt:");
    /* select drawing to page #0 */
    setactivepage(0);
    /* output a message on page #0 */
    outtextxy(x, y, "This is page #0.");
    outtextxy(x, y+ht, "Press any key to view page #1:");
    getch();
    /* select page #1 as the visible page */
    setvisualpage(1);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }


    º¯ÊýÃû: setallpallette
    ¹¦ ÄÜ: °´Ö¸¶¨·½Ê½¸Ä±äËùÓеĵ÷É«°åÑÕÉ«
    ÓÃ ·¨: void far setallpallette(struct palette, far *pallette);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    struct palettetype pal;
    int color, maxcolor, ht;
    int y = 10;
    char msg[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    maxcolor = getmaxcolor();
    ht = 2 * textheight("W");
    /* grab a copy of the palette */
    getpalette(&pal);
    /* display the default palette colors */
    for (color=1; color<=maxcolor; color++)
    {
    setcolor(color);
    sprintf(msg, "Color: %d", color);
    outtextxy(1, y, msg);
    y += ht;
    }
    /* wait for a key */
    getch();
    /* black out the colors one by one */
    for (color=1; color<=maxcolor; color++)
    {
    setpalette(color, BLACK);
    getch();
    }
    /* restore the palette colors */
    setallpalette(&pal);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }


    º¯ÊýÃû: setaspectratio
    ¹¦ ÄÜ: ÉèÖÃͼÐÎ×ݺá±È
    ÓÃ ·¨: void far setaspectratio(int xasp, int yasp);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int xasp, yasp, midx, midy;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    setcolor(getmaxcolor());
    /* get current aspect ratio settings */
    getaspectratio(&xasp, &yasp);
    /* draw normal circle */
    circle(midx, midy, 100);
    getch();
    /* claer the screen */
    cleardevice();
    /* adjust the aspect for a wide circle */
    setaspectratio(xasp/2, yasp);
    circle(midx, midy, 100);
    getch();
    /* adjust the aspect for a narrow circle */
    cleardevice();
    setaspectratio(xasp, yasp/2);
    circle(midx, midy, 100);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }


    º¯ÊýÃû: setbkcolor
    ¹¦ ÄÜ: Óõ÷É«°åÉèÖõ±Ç°±³¾°ÑÕÉ«
    ÓÃ ·¨: void far setbkcolor(int color);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* select a driver and mode that supports */
    /* multiple background colors. */
    int gdriver = EGA, gmode = EGAHI, errorcode;
    int bkcol, maxcolor, x, y;
    char msg[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    /* maximum color index supported */
    maxcolor = getmaxcolor();
    /* for centering text messages */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    x = getmaxx() / 2;
    y = getmaxy() / 2;
    /* loop through the available colors */
    for (bkcol=0; bkcol<=maxcolor; bkcol++)
    {
    /* clear the screen */
    cleardevice();
    /* select a new background color */
    setbkcolor(bkcol);
    /* output a messsage */
    if (bkcol == WHITE)
    setcolor(EGA_BLUE);
    sprintf(msg, "Background color: %d", bkcol);
    outtextxy(x, y, msg);
    getch();
    }
    /* clean up */
    closegraph();
    return 0;
    }


    º¯ÊýÃû: setblock
    ¹¦ ÄÜ: ÐÞ¸ÄÏÈÇ°ÒÑ·ÖÅäµÄDOS´æ´¢¶Î´óС
    ÓÃ ·¨: int setblock(int seg, int newsize);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    unsigned int size, segp;
    int stat;
    size = 64; /* (64 x 16) = 1024 bytes */
    stat = allocmem(size, &segp);
    if (stat == -1)
    printf("Allocated memory at segment: %X\n", segp);
    else
    {
    printf("Failed: maximum number of paragraphs available is %d\n",
    stat);
    exit(1);
    }
    stat = setblock(segp, size * 2);
    if (stat == -1)
    printf("Expanded memory block at segment: %X\n", segp);
    else
    printf("Failed: maximum number of paragraphs available is %d\n",
    stat);
    freemem(segp);
    return 0;
    }


    º¯ÊýÃû: setbuf
    ¹¦ ÄÜ: °Ñ»º³åÇøÓëÁ÷ÏàÁª
    ÓÃ ·¨: void setbuf(FILE *steam, char *buf);
    ³ÌÐòÀý:
    #include ;
    /* BUFSIZ is defined in stdio.h */
    char outbuf[BUFSIZ];
    int main(void)
    {
    /* attach a buffer to the standard output stream */
    setbuf(stdout, outbuf);
    /* put some characters into the buffer */
    puts("This is a test of buffered output.\n\n");
    puts("This output will go into outbuf\n");
    puts("and won't appear until the buffer\n");
    puts("fills up or we flush the stream.\n");
    /* flush the output buffer */
    fflush(stdout);
    return 0;
    }


    º¯ÊýÃû: setcbrk
    ¹¦ ÄÜ: ÉèÖÃControl-break
    ÓÃ ·¨: int setcbrk(int value);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    int break_flag;
    printf("Enter 0 to turn control break off\n");
    printf("Enter 1 to turn control break on\n");
    break_flag = getch() - 0;
    setcbrk(break_flag);
    if (getcbrk())
    printf("Cntrl-brk flag is on\n");
    else
    printf("Cntrl-brk flag is off\n");
    return 0;
    }



    º¯ÊýÃû: setcolor
    ¹¦ ÄÜ: ÉèÖõ±Ç°»­ÏßÑÕÉ«
    ÓÃ ·¨: void far setcolor(int color);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* select a driver and mode that supports */
    /* multiple drawing colors. */
    int gdriver = EGA, gmode = EGAHI, errorcode;
    int color, maxcolor, x, y;
    char msg[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    /* maximum color index supported */
    maxcolor = getmaxcolor();
    /* for centering text messages */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    x = getmaxx() / 2;
    y = getmaxy() / 2;
    /* loop through the available colors */
    for (color=1; color<=maxcolor; color++)
    {
    /* clear the screen */
    cleardevice();
    /* select a new background color */
    setcolor(color);
    /* output a messsage */
    sprintf(msg, "Color: %d", color);
    outtextxy(x, y, msg);
    getch();
    }
    /* clean up */
    closegraph();
    return 0;
    }


    º¯ÊýÃû: setdate
    ¹¦ ÄÜ: ÉèÖÃDOSÈÕÆÚ
    ÓÃ ·¨: void setdate(struct date *dateblk);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    struct date reset;
    struct date save_date;
    getdate(&save_date);
    printf("Original date:\n");
    system("date");
    reset.da_year = 2001;
    reset.da_day = 1;
    reset.da_mon = 1;
    setdate(&reset);
    printf("Date after setting:\n");
    system("date");
    setdate(&save_date);
    printf("Back to original date:\n");
    system("date");
    return 0;
    }


    º¯ÊýÃû: setdisk
    ¹¦ ÄÜ: ÉèÖõ±Ç°´ÅÅÌÇý¶¯Æ÷
    ÓÃ ·¨: int setdisk(int drive);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    int save, disk, disks;
    /* save original drive */
    save = getdisk();
    /* print number of logic drives */
    disks = setdisk(save);
    printf("%d logical drives on the system\n\n", disks);
    /* print the drive letters available */
    printf("Available drives:\n");
    for (disk = 0;disk < 26;++disk)
    {
    setdisk(disk);
    if (disk == getdisk())
    printf("%c: drive is available\n", disk + 'a');
    }
    setdisk(save);
    return 0;
    }


    º¯ÊýÃû: setdta
    ¹¦ ÄÜ: ÉèÖôÅÅÌ´«ÊäÇøµØÖ·
    ÓÃ ·¨: void setdta(char far *dta);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char line[80], far *save_dta;
    char buffer[256] = "SETDTA test!";
    struct fcb blk;
    int result;
    /* get new file name from user */
    printf("Enter a file name to create:");
    gets(line);
    /* parse the new file name to the dta */
    parsfnm(line, &blk, 1);
    printf("%d %s\n", blk.fcb_drive, blk.fcb_name);
    /* request DOS services to create file */
    if (bdosptr(0x16, &blk, 0) == -1)
    {
    perror("Error creating file");
    exit(1);
    }
    /* save old dta and set new dta */
    save_dta = getdta();
    setdta(buffer);
    /* write new records */
    blk.fcb_recsize = 256;
    blk.fcb_random = 0L;
    result = randbwr(&blk, 1);
    printf("result = %d\n", result);
    if (!result)
    printf("Write OK\n");
    else
    {
    perror("Disk error");
    exit(1);
    }
    /* request DOS services to close the file */
    if (bdosptr(0x10, &blk, 0) == -1)
    {
    perror("Error closing file");
    exit(1);
    }
    /* reset the old dta */
    setdta(save_dta);
    return 0;
    }


    º¯ÊýÃû: setfillpattern
    ¹¦ ÄÜ: Ñ¡ÔñÓû§¶¨ÒåµÄÌî³äģʽ
    ÓÃ ·¨: void far setfillpattern(char far *upattern, int color);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int maxx, maxy;
    /* a user defined fill pattern */
    char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00};
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    maxx = getmaxx();
    maxy = getmaxy();
    setcolor(getmaxcolor());
    /* select a user defined fill pattern */
    setfillpattern(pattern, getmaxcolor());
    /* fill the screen with the pattern */
    bar(0, 0, maxx, maxy);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }


    º¯ÊýÃû: setfillstyle
    ¹¦ ÄÜ: ÉèÖÃÌî³äģʽºÍÑÕÉ«
    ÓÃ ·¨: void far setfillstyle(int pattern, int color);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #include ;
    /* the names of the fill styles supported */
    char *fname[] = { "EMPTY_FILL",
    "SOLID_FILL",
    "LINE_FILL",
    "LTSLASH_FILL",
    "SLASH_FILL",
    "BKSLASH_FILL",
    "LTBKSLASH_FILL",
    "HATCH_FILL",
    "XHATCH_FILL",
    "INTERLEAVE_FILL",
    "WIDE_DOT_FILL",
    "CLOSE_DOT_FILL",
    "USER_FILL"
    };
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int style, midx, midy;
    char stylestr[40];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    for (style = EMPTY_FILL; style < USER_FILL; style++)
    {
    /* select the fill style */
    setfillstyle(style, getmaxcolor());
    /* convert style into a string */
    strcpy(stylestr, fname[style]);
    /* fill a bar */
    bar3d(0, 0, midx-10, midy, 0, 0);
    /* output a message */
    outtextxy(midx, midy, stylestr);
    /* wait for a key */
    getch();
    cleardevice();
    }
    /* clean up */
    getch();
    closegraph();
    return 0;
    }


    º¯ÊýÃû: setftime
    ¹¦ ÄÜ: ÉèÖÃÎļþÈÕÆÚºÍʱ¼ä
    ÓÃ ·¨: int setftime(int handle, struct ftime *ftimep);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    struct ftime filet;
    FILE *fp;
    if ((fp = fopen("TEST.$$$", "w")) == NULL)
    {
    perror("Error:");
    exit(1);
    }
    fprintf(fp, "testing...\n");
    /* load ftime structure with new time and date */
    filet.ft_tsec = 1;
    filet.ft_min = 1;
    filet.ft_hour = 1;
    filet.ft_day = 1;
    filet.ft_month = 1;
    filet.ft_year = 21;
    /* show current directory for time and date */
    system("dir TEST.$$$");
    /* change the time and date stamp*/
    setftime(fileno(fp), &filet);
    /* close and remove the temporary file */
    fclose(fp);
    system("dir TEST.$$$");
    unlink("TEST.$$$");
    return 0;
    }


    º¯ÊýÃû: setgraphbufsize
    ¹¦ ÄÜ: ¸Ä±äÄÚ²¿Í¼Ðλº³åÇøµÄ´óС
    ÓÃ ·¨: unsigned far setgraphbufsize(unsigned bufsize);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #define BUFSIZE 1000 /* internal graphics buffer size */
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int x, y, oldsize;
    char msg[80];
    /* set the size of the internal graphics buffer */
    /* before making a call to initgraph. */
    oldsize = setgraphbufsize(BUFSIZE);
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    x = getmaxx() / 2;
    y = getmaxy() / 2;
    /* output some messages */
    sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(x, y, msg);
    sprintf(msg, "Old graphics buffer size: %d", oldsize);
    outtextxy(x, y+textheight("W"), msg);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }



    º¯ÊýÃû: setgraphmode
    ¹¦ ÄÜ: ½«ÏµÍ³ÉèÖóÉͼÐÎģʽÇÒÇåÆÁ
    ÓÃ ·¨: void far setgraphmode(int mode);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int x, y;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    x = getmaxx() / 2;
    y = getmaxy() / 2;
    /* output a message */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(x, y, "Press any key to exit graphics:");
    getch();
    /* restore system to text mode */
    restorecrtmode();
    printf("We're now in text mode.\n");
    printf("Press any key to return to graphics mode:");
    getch();
    /* return to graphics mode */
    setgraphmode(getgraphmode());
    /* output a message */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(x, y, "We're back in graphics mode.");
    outtextxy(x, y+textheight("W"), "Press any key to halt:");
    /* clean up */
    getch();
    closegraph();
    return 0;
    }

  7. hfh08 ÓÚ 2006-08-21 15:57:44·¢±í:

    º¯ÊýÃû: harderr
    ¹¦ ÄÜ: ½¨Á¢Ò»¸öÓ²¼þ´íÎó´¦Àí³ÌÐò
    ÓÃ ·¨: void harderr(int (*fptr)());
    ³ÌÐòÀý:
    /*This program will trap disk errors and prompt
    the user for action. Try running it with no
    disk in drive A: to invoke its functions.*/
    #include ;
    #include ;
    #include ;
    #define IGNORE 0
    #define RETRY 1
    #define ABORT 2
    int buf[500];
    /*define the error messages for trapping disk problems*/
    static char *err_msg[] = {
    "write protect",
    "unknown unit",
    "drive not ready",
    "unknown command",
    "data error (CRC)",
    "bad request",
    "seek error",
    "unknown media type",
    "sector not found",
    "printer out of paper",
    "write fault",
    "read fault",
    "general failure",
    "reserved",
    "reserved",
    "invalid disk change"
    };
    error_win(char *msg)
    {
    int retval;
    cputs(msg);
    /*prompt for user to press a key to abort, retry, ignore*/
    while(1)
    {
    retval= getch();
    if (retval == 'a' || retval == 'A')
    {
    retval = ABORT;
    break;
    }
    if (retval == 'r' || retval == 'R')
    {
    retval = RETRY;
    break;
    }
    if (retval == 'i' || retval == 'I')
    {
    retval = IGNORE;
    break;
    }
    }
    return(retval);
    }
    /*pragma warn -par reduces warnings which occur
    due to the non use of the parameters errval,
    bp and si to the handler.*/
    #pragma warn -par
    int handler(int errval,int ax,int bp,int si)
    {
    static char msg[80];
    unsigned di;
    int drive;
    int errorno;
    di= _DI;
    /*if this is not a disk error then it was
    another device having trouble*/
    if (ax < 0)
    {
    /* report the error */
    error_win("Device error");
    /* and return to the program directly requesting abort */
    hardretn(ABORT);
    }
    /* otherwise it was a disk error */
    drive = ax & 0x00FF;
    errorno = di & 0x00FF;
    /* report which error it was */
    sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
    err_msg[errorno], 'A' + drive);
    /*
    return to the program via dos interrupt 0x23 with abort, retry,
    or ignore as input by the user.
    */
    hardresume(error_win(msg));
    return ABORT;
    }
    #pragma warn +par
    int main(void)
    {
    /*
    install our handler on the hardware problem interrupt
    */
    harderr(handler);
    clrscr();
    printf("Make sure there is no disk in drive A:\n");
    printf("Press any key ....\n");
    getch();
    printf("Trying to access drive A:\n");
    printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
    return 0;
    }


    º¯ÊýÃû: hardresume
    ¹¦ ÄÜ: Ó²¼þ´íÎó´¦Àíº¯Êý
    ÓÃ ·¨: void hardresume(int rescode);
    ³ÌÐòÀý:

    /* This program will trap disk errors and prompt the user for action. */
    /* Try running it with no disk in drive A: to invoke its functions */
    #include ;
    #include ;
    #include ;
    #define IGNORE 0
    #define RETRY 1
    #define ABORT 2
    int buf[500];
    /* define the error messages for trapping disk problems */
    static char *err_msg[] = {
    "write protect",
    "unknown unit",
    "drive not ready",
    "unknown command",
    "data error (CRC)",
    "bad request",
    "seek error",
    "unknown media type",
    "sector not found",
    "printer out of paper",
    "write fault",
    "read fault",
    "general failure",
    "reserved",
    "reserved",
    "invalid disk change"
    };
    error_win(char *msg)
    {
    int retval;
    cputs(msg);
    /* prompt for user to press a key to abort, retry, ignore */
    while(1)
    {
    retval= getch();
    if (retval == 'a' || retval == 'A')
    {
    retval = ABORT;
    break;
    }
    if (retval == 'r' || retval == 'R')
    {
    retval = RETRY;
    break;
    }
    if (retval == 'i' || retval == 'I')
    {
    retval = IGNORE;
    break;
    }
    }
    return(retval);
    }
    /* pragma warn -par reduces warnings which occur due to the non use */
    /* of the parameters errval, bp and si to the handler. */
    #pragma warn -par
    int handler(int errval,int ax,int bp,int si)
    {
    static char msg[80];
    unsigned di;
    int drive;
    int errorno;
    di= _DI;
    /* if this is not a disk error then it was another device having trouble */
    if (ax < 0)
    {
    /* report the error */
    error_win("Device error");
    /* and return to the program directly
    requesting abort */
    hardretn(ABORT);
    }
    /* otherwise it was a disk error */
    drive = ax & 0x00FF;
    errorno = di & 0x00FF;
    /* report which error it was */
    sprintf(msg, "Error: %s on drive %c\r\nA)bort, R)etry, I)gnore: ",
    err_msg[errorno], 'A' + drive);
    /* return to the program via dos interrupt 0x23 with abort, retry */
    /* or ignore as input by the user. */
    hardresume(error_win(msg));
    return ABORT;
    }
    #pragma warn +par
    int main(void)
    {
    /* install our handler on the hardware problem interrupt */
    harderr(handler);
    clrscr();
    printf("Make sure there is no disk in drive A:\n");
    printf("Press any key ....\n");
    getch();
    printf("Trying to access drive A:\n");
    printf("fopen returned %p\n",fopen("A:temp.dat", "w"));
    return 0;
    }


    º¯ÊýÃû: highvideo
    ¹¦ ÄÜ: Ñ¡Ôñ¸ßÁÁ¶ÈÎı¾×Ö·û
    ÓÃ ·¨: void highvideo(void);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    clrscr();
    lowvideo();
    cprintf("Low Intensity text\r\n");
    highvideo();
    gotoxy(1,2);
    cprintf("High Intensity Text\r\n");
    return 0;
    }


    º¯ÊýÃû: hypot
    ¹¦ ÄÜ: ¼ÆËãÖ±½ÇÈý½ÇÐεÄб±ß³¤
    ÓÃ ·¨: double hypot(double x, double y);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    double result;
    double x = 3.0;
    double y = 4.0;
    result = hypot(x, y);
    printf("The hypotenuse is: %lf\n", result);
    return 0;
    }
    º¯ÊýÃû: imagesize
    ¹¦ ÄÜ: ·µ»Ø±£´æλͼÏñËùÐèµÄ×Ö½ÚÊý
    ÓÃ ·¨: unsigned far imagesize(int left, int top, int right, int bottom);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #define ARROW_SIZE 10
    void draw_arrow(int x, int y);
    int main(void)
    {
    /* request autodetection */
    int gdriver = DETECT, gmode, errorcode;
    void *arrow;
    int x, y, maxx;
    unsigned int size;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    maxx = getmaxx();
    x = 0;
    y = getmaxy() / 2;
    /* draw the image to be grabbed */
    draw_arrow(x, y);
    /* calculate the size of the image */
    size = imagesize(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE);
    /* allocate memory to hold the image */
    arrow = malloc(size);
    /* grab the image */
    getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow);
    /* repeat until a key is pressed */
    while (!kbhit())
    {
    /* erase old image */
    putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
    x += ARROW_SIZE;
    if (x >;= maxx)
    x = 0;
    /* plot new image */
    putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);
    }
    /* clean up */
    free(arrow);
    closegraph();
    return 0;
    }
    void draw_arrow(int x, int y)
    {
    /* draw an arrow on the screen */
    moveto(x, y);
    linerel(4*ARROW_SIZE, 0);
    linerel(-2*ARROW_SIZE, -1*ARROW_SIZE);
    linerel(0, 2*ARROW_SIZE);
    linerel(2*ARROW_SIZE, -1*ARROW_SIZE);
    }



    º¯ÊýÃû: initgraph
    ¹¦ ÄÜ: ³õʼ»¯Í¼ÐÎϵͳ
    ÓÃ ·¨: void far initgraph(int far *graphdriver, int far *graphmode,
    char far *pathtodriver);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    /* initialize graphics mode */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* return with error code */
    }
    /* draw a line */
    line(0, 0, getmaxx(), getmaxy());
    /* clean up */
    getch();
    closegraph();
    return 0;
    }


    º¯ÊýÃû: inport
    ¹¦ ÄÜ: ´ÓÓ²¼þ¶Ë¿ÚÖÐÊäÈë
    ÓÃ ·¨: int inp(int protid);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    int result;
    int port = 0; /* serial port 0 */
    result = inport(port);
    printf("Word read from port %d = 0x%X\n", port, result);
    return 0;
    }


    º¯ÊýÃû: insline
    ¹¦ ÄÜ: ÔÚÎı¾´°¿ÚÖвåÈëÒ»¸ö¿ÕÐÐ
    ÓÃ ·¨: void insline(void);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    clrscr();
    cprintf("INSLINE inserts an empty line in the text window\r\n");
    cprintf("at the cursor position using the current text\r\n");
    cprintf("background color. All lines below the empty one\r\n");
    cprintf("move down one line and the bottom line scrolls\r\n");
    cprintf("off the bottom of the window.\r\n");
    cprintf("\r\nPress any key to continue:");
    gotoxy(1, 3);
    getch();
    insline();
    getch();
    return 0;
    }



    º¯ÊýÃû: installuserdriver
    ¹¦ ÄÜ: °²×°É豸Çý¶¯³ÌÐòµ½BGIÉ豸Çý¶¯³ÌÐò±íÖÐ
    ÓÃ ·¨: int far installuserdriver(char far *name, int (*detect)(void));
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    /* function prototypes */
    int huge detectEGA(void);
    void checkerrors(void);
    int main(void)
    {
    int gdriver, gmode;
    /* install a user written device driver */
    gdriver = installuserdriver("EGA", detectEGA);
    /* must force use of detection routine */
    gdriver = DETECT;
    /* check for any installation errors */
    checkerrors();
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* check for any initialization errors */
    checkerrors();
    /* draw a line */
    line(0, 0, getmaxx(), getmaxy());
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    /* detects EGA or VGA cards */
    int huge detectEGA(void)
    {
    int driver, mode, sugmode = 0;
    detectgraph(&driver, &mode);
    if ((driver == EGA) || (driver == VGA))
    /* return suggested video mode number */
    return sugmode;
    else
    /* return an error code */
    return grError;
    }
    /* check for and report any graphics errors */
    void checkerrors(void)
    {
    int errorcode;
    /* read result of last graphics operation */
    errorcode = graphresult();
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1);
    }
    }
    º¯ÊýÃû: installuserfont
    ¹¦ ÄÜ: °²×°Î´Ç¶ÈëBGIϵͳµÄ×ÖÌåÎļþ(CHR)
    ÓÃ ·¨: int far installuserfont(char far *name);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    /* function prototype */
    void checkerrors(void);
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode;
    int userfont;
    int midx, midy;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* check for any initialization errors */
    checkerrors();
    /* install a user defined font file */
    userfont = installuserfont("USER.CHR");
    /* check for any installation errors */
    checkerrors();
    /* select the user font */
    settextstyle(userfont, HORIZ_DIR, 4);
    /* output some text */
    outtextxy(midx, midy, "Testing!");
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    /* check for and report any graphics errors */
    void checkerrors(void)
    {
    int errorcode;
    /* read result of last graphics operation */
    errorcode = graphresult();
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1);
    }
    }



    º¯ÊýÃû: int86
    ¹¦ ÄÜ: ͨÓÃ8086ÈíÖжϽӿÚ
    ÓÃ ·¨: int int86(int intr_num, union REGS *inregs, union REGS *outregs);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #define VIDEO 0x10
    void movetoxy(int x, int y)
    {
    union REGS regs;
    regs.h.ah = 2; /* set cursor postion */
    regs.h.dh = y;
    regs.h.dl = x;
    regs.h.bh = 0; /* video page 0 */
    int86(VIDEO, &s, &s);
    }
    int main(void)
    {
    clrscr();
    movetoxy(35, 10);
    printf("Hello\n");
    return 0;
    }


    º¯ÊýÃû: int86x
    ¹¦ ÄÜ: ͨÓÃ8086ÈíÖжϽӿÚ
    ÓÃ ·¨: int int86x(int intr_num, union REGS *insegs, union REGS *outregs,
    struct SREGS *segregs);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char filename[80];
    union REGS inregs, outregs;
    struct SREGS segregs;
    printf("Enter filename: ");
    gets(filename);
    inregs.h.ah = 0x43;
    inregs.h.al = 0x21;
    inregs.x.dx = FP_OFF(filename);
    segregs.ds = FP_SEG(filename);
    int86x(0x21, &inregs, &outregs, &segregs);
    printf("File attribute: %X\n", outregs.x.cx);
    return 0;
    }



    º¯ÊýÃû: intdos
    ¹¦ ÄÜ: ͨÓÃDOS½Ó¿Ú
    ÓÃ ·¨: int intdos(union REGS *inregs, union REGS *outregs);
    ³ÌÐòÀý:
    #include ;
    #include ;
    /* deletes file name; returns 0 on success, nonzero on failure */
    int delete_file(char near *filename)
    {
    union REGS regs;
    int ret;
    regs.h.ah = 0x41; /* delete file */
    regs.x.dx = (unsigned) filename;
    ret = intdos(&s, &s);
    /* if carry flag is set, there was an error */
    return(regs.x.cflag ? ret : 0);
    }
    int main(void)
    {
    int err;
    err = delete_file("NOTEXIST.$$$");
    if (!err)
    printf("Able to delete NOTEXIST.$$$\n");
    else
    printf("Not Able to delete NOTEXIST.$$$\n");
    return 0;
    }



    º¯ÊýÃû: intdosx
    ¹¦ ÄÜ: ͨÓÃDOSÖжϽӿÚ
    ÓÃ ·¨: int intdosx(union REGS *inregs, union REGS *outregs,
    struct SREGS *segregs);
    ³ÌÐòÀý:
    #include ;
    #include ;
    /* deletes file name; returns 0 on success, nonzero on failure */
    int delete_file(char far *filename)
    {
    union REGS regs; struct SREGS sregs;
    int ret;
    regs.h.ah = 0x41; /* delete file */
    regs.x.dx = FP_OFF(filename);
    sregs.ds = FP_SEG(filename);
    ret = intdosx(&s, &s, &sregs);
    /* if carry flag is set, there was an error */
    return(regs.x.cflag ? ret : 0);
    }
    int main(void)
    {
    int err;
    err = delete_file("NOTEXIST.$$$");
    if (!err)
    printf("Able to delete NOTEXIST.$$$\n");
    else
    printf("Not Able to delete NOTEXIST.$$$\n");
    return 0;
    }


    º¯ÊýÃû: intr
    ¹¦ ÄÜ: ¸Ä±äÈíÖжϽӿÚ
    ÓÃ ·¨: void intr(int intr_num, struct REGPACK *preg);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #define CF 1 /* Carry flag */
    int main(void)
    {
    char directory[80];
    struct REGPACK reg;
    printf("Enter directory to change to: ");
    gets(directory);
    reg.r_ax = 0x3B << 8; /* shift 3Bh into AH */
    reg.r_dx = FP_OFF(directory);
    reg.r_ds = FP_SEG(directory);
    intr(0x21, &);
    if (reg.r_flags & CF)
    printf("Directory change failed\n");
    getcwd(directory, 80);
    printf("The current directory is: %s\n", directory);
    return 0;
    }


    º¯ÊýÃû: ioctl
    ¹¦ ÄÜ: ¿ØÖÆI/OÉ豸
    ÓÃ ·¨: int ioctl(int handle, int cmd[,int *argdx, int argcx]);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    int stat;
    /* use func 8 to determine if the default drive is removable */
    stat = ioctl(0, 8, 0, 0);
    if (!stat)
    printf("Drive %c is removable.\n", getdisk() + 'A');
    else
    printf("Drive %c is not removable.\n", getdisk() + 'A');
    return 0;
    }



    º¯ÊýÃû: isatty
    ¹¦ ÄÜ: ¼ì²éÉ豸ÀàÐÍ
    ÓÃ ·¨: int isatty(int handle);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    int handle;
    handle = fileno(stdprn);
    if (isatty(handle))
    printf("Handle %d is a device type\n", handle);
    else
    printf("Handle %d isn't a device type\n", handle);
    return 0;
    }



    º¯ÊýÃû: itoa
    ¹¦ ÄÜ: °ÑÒ»ÕûÊýת»»Îª×Ö·û´®
    ÓÃ ·¨: char *itoa(int value, char *string, int radix);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    int number = 12345;
    char string[25];
    itoa(number, string, 10);
    printf("integer = %d string = %s\n", number, string);
    return 0;
    }
    º¯ÊýÃû: kbhit
    ¹¦ ÄÜ: ¼ì²éµ±Ç°°´Ïµļü
    ÓÃ ·¨: int kbhit(void);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    cprintf("Press any key to continue:");
    while (!kbhit()) /* do nothing */ ;
    cprintf("\r\nA key was pressed...\r\n");
    return 0;
    }



    º¯ÊýÃû: keep
    ¹¦ ÄÜ: Í˳ö²¢¼ÌÐøפÁô
    ÓÃ ·¨: void keep(int status, int size);
    ³ÌÐòÀý:
    /***NOTE:
    This is an interrupt service routine. You
    can NOT compile this program with Test
    Stack Overflow turned on and get an
    executable file which will operate
    correctly. Due to the nature of this
    function the formula used to compute
    the number of paragraphs may not
    necessarily work in all cases. Use with
    care! Terminate Stay Resident (TSR)
    programs are complex and no other support
    for them is provided. Refer to the
    MS-DOS technical documentation
    for more information. */
    #include ;
    /* The clock tick interrupt */
    #define INTR 0x1C
    /* Screen attribute (blue on grey) */
    #define ATTR 0x7900
    /* reduce heaplength and stacklength
    to make a smaller program in memory */
    extern unsigned _heaplen = 1024;
    extern unsigned _stklen = 512;
    void interrupt ( *oldhandler)(void);
    void interrupt handler(void)
    {
    unsigned int (far *screen)[80];
    static int count;
    /* For a color screen the video memory
    is at B800:0000. For a monochrome
    system use B000:000 */
    screen = MK_FP(0xB800,0);
    /* increase the counter and keep it
    within 0 to 9 */
    count++;
    count %= 10;
    /* put the number on the screen */
    screen[0][79] = count + '0' + ATTR;
    /* call the old interrupt handler */
    oldhandler();
    }
    int main(void)
    {
    /* get the address of the current clock
    tick interrupt */
    oldhandler = getvect(INTR);
    /* install the new interrupt handler */
    setvect(INTR, handler);
    /* _psp is the starting address of the
    program in memory. The top of the stack
    is the end of the program. Using _SS and
    _SP together we can get the end of the
    stack. You may want to allow a bit of
    saftey space to insure that enough room
    is being allocated ie:
    (_SS + ((_SP + safety space)/16) - _psp)
    */
    keep(0, (_SS + (_SP/16) - _psp));
    return 0;
    }
    main()Ö÷º¯Êý
    ÿһC ³ÌÐò¶¼±ØÐëÓÐÒ»main()º¯Êý, ¿ÉÒÔ¸ù¾Ý×Ô¼ºµÄ°®ºÃ°ÑËü·ÅÔÚ³ÌÐòµÄij
    ¸öµØ·½¡£ÓÐЩ³ÌÐòÔ±°ÑËü·ÅÔÚ×îÇ°Ãæ, ¶øÁíһЩ³ÌÐòÔ±°ÑËü·ÅÔÚ×îºóÃæ, ÎÞÂÛ·Å
    ÔÚÄĸöµØ·½, ÒÔϼ¸µã˵Ã÷¶¼ÊÇÊʺϵġ£
    1. main() ²ÎÊý
    ÔÚTurbo C2.0Æô¶¯¹ý³ÌÖÐ, ´«µÝmain()º¯ÊýÈý¸ö²ÎÊý: argc, argvºÍenv¡£
    * argc: ÕûÊý, Ϊ´«¸ømain()µÄÃüÁîÐвÎÊý¸öÊý¡£
    * argv: ×Ö·û´®Êý×é¡£
    ÔÚDOS 3.X °æ±¾ÖÐ, argv[0] Ϊ³ÌÐòÔËÐеÄȫ·¾¶Ãû; ¶ÔDOS 3.0
    ÒÔϵİ汾, argv[0]Ϊ¿Õ´®("") ¡£
    argv[1] ΪÔÚDOSÃüÁîÐÐÖÐÖ´ÐгÌÐòÃûºóµÄµÚÒ»¸ö×Ö·û´®;
    argv[2] ΪִÐгÌÐòÃûºóµÄµÚ¶þ¸ö×Ö·û´®;
    ...
    argv[argc]ΪNULL¡£
    *env: °²·û´®Êý×é¡£env[] µÄÿһ¸öÔªËض¼°üº¬ENVVAR=valueÐÎʽµÄ×Ö·û
    ´®¡£ÆäÖÐENVVARΪ»·¾³±äÁ¿ÈçPATH»ò87¡£value ΪENVVARµÄ¶ÔÓ¦ÖµÈçC:\DOS, C:
    \TURBOC(¶ÔÓÚPATH) »òYES(¶ÔÓÚ87)¡£
    Turbo C2.0Æô¶¯Ê±×ÜÊÇ°ÑÕâÈý¸ö²ÎÊý´«µÝ¸ømain()º¯Êý, ¿ÉÒÔÔÚÓû§³ÌÐòÖÐ
    ˵Ã÷(»ò²»ËµÃ÷)ËüÃÇ, Èç¹û˵Ã÷Á˲¿·Ö(»òÈ«²¿)²ÎÊý, ËüÃǾͳÉΪmain()×Ó³ÌÐò
    µÄ¾Ö²¿±äÁ¿¡£
    Çë×¢Òâ: Ò»µ©Ïë˵Ã÷ÕâЩ²ÎÊý, Ôò±ØÐë°´argc, argv, env µÄ˳Ðò, ÈçÒÔÏÂ
    µÄÀý×Ó:
    main()
    main(int argc)
    main(int argc, char *argv[])
    main(int argc, char *argv[], char *env[])
    ÆäÖеڶþÖÖÇé¿öÊǺϷ¨µÄ, µ«²»³£¼û, ÒòΪÔÚ³ÌÐòÖкÜÉÙÓÐÖ»ÓÃargc, ¶ø²»
    ÓÃargv[]µÄÇé¿ö¡£
    ÒÔÏÂÌṩһÑùÀý³ÌÐòEXAMPLE.EXE, ÑÝʾÈçºÎÔÚmain()º¯ÊýÖÐʹÓÃÈý¸ö²ÎÊý:
    /*program name EXAMPLE.EXE*/
    #include ;
    #include ;
    main(int argc, char *argv[], char *env[])
    {
    int i;
    printf("These are the %d command- line arguments passed to
    main:\n\n", argc);
    for(i=0; i<=argc; i++)
    printf("argv[%d]:%s\n", i, argv[i]);
    printf("\nThe environment string(s)on this system are:\n\n");
    for(i=0; env[i]!=NULL; i++)
    printf(" env[%d]:%s\n", i, env[i]);
    }
    Èç¹ûÔÚDOS Ìáʾ·ûÏÂ, °´ÒÔÏ·½Ê½ÔËÐÐEXAMPLE.EXE:
    C:\example first_argument "argument with blanks" 3 4 "last but
    one" stop!
    ×¢Òâ: ¿ÉÒÔÓÃË«ÒýºÅÀ¨ÆðÄÚº¬¿Õ¸ñµÄ²ÎÊý, Èç±¾ÀýÖеÄ: " argument
    with blanks"ºÍ"Last but one")¡£
    ½á¹ûÊÇÕâÑùµÄ:
    The value of argc is 7
    These are the 7 command-linearguments passed to main:
    argv[0]:C:\TURBO\EXAMPLE.EXE
    argv[1]:first_argument
    argv[2]:argument with blanks
    argv[3]:3
    argv[4]:4
    argv[5]:last but one
    argv[6]:stop!
    argv[7]:(NULL)
    The environment string(s) on this system are:
    env[0]: COMSPEC=C:\COMMAND.COM
    env[1]: PROMPT=$P$G /*ÊÓ¾ßÌåÉèÖöø¶¨*/
    env[2]: PATH=C:\DOS;C:\TC /*ÊÓ¾ßÌåÉèÖöø¶¨*/

    Ó¦¸ÃÌáÐѵÄÊÇ: ´«ËÍmain() º¯ÊýµÄÃüÁîÐвÎÊýµÄ×î´ó³¤¶ÈΪ128 ¸ö×Ö·û (°ü
    À¨²ÎÊý¼äµÄ¿Õ¸ñ), ÕâÊÇÓÉDOS ÏÞÖƵġ£

    º¯ÊýÃû: matherr
    ¹¦ ÄÜ: Óû§¿ÉÐ޸ĵÄÊýѧ´íÎó´¦Àí³ÌÐò
    ÓÃ ·¨: int matherr(struct exception *e);
    ³ÌÐòÀý:
    /* This is a user-defined matherr function that prevents
    any error messages from being printed. */
    #include;
    int matherr(struct exception *a)
    {
    return 1;
    }



    º¯ÊýÃû: memccpy
    ¹¦ ÄÜ: ´ÓÔ´sourceÖп½±´n¸ö×Ö½Úµ½Ä¿±êdestinÖÐ
    ÓÃ ·¨: void *memccpy(void *destin, void *source, unsigned char ch,
    unsigned n);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char *src = "This is the source string";
    char dest[50];
    char *ptr;
    ptr = memccpy(dest, src, 'c', strlen(src));
    if (ptr)
    {
    *ptr = '\0';
    printf("The character was found: %s\n", dest);
    }
    else
    printf("The character wasn't found\n");
    return 0;
    }


    º¯ÊýÃû: malloc
    ¹¦ ÄÜ: ÄÚ´æ·ÖÅ亯Êý
    ÓÃ ·¨: void *malloc(unsigned size);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char *str;
    /* allocate memory for string */
    /* This will generate an error when compiling */
    /* with C++, use the new operator instead. */
    if ((str = malloc(10)) == NULL)
    {
    printf("Not enough memory to allocate buffer\n");
    exit(1); /* terminate program if out of memory */
    }
    /* copy "Hello" into string */
    strcpy(str, "Hello");
    /* display string */
    printf("String is %s\n", str);
    /* free memory */
    free(str);
    return 0;
    }



    º¯ÊýÃû: memchr
    ¹¦ ÄÜ: ÔÚÊý×éµÄÇ°n¸ö×Ö½ÚÖÐËÑË÷×Ö·û
    ÓÃ ·¨: void *memchr(void *s, char ch, unsigned n);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char str[17];
    char *ptr;
    strcpy(str, "This is a string");
    ptr = memchr(str, 'r', strlen(str));
    if (ptr)
    printf("The character 'r' is at position: %d\n", ptr - str);
    else
    printf("The character was not found\n");
    return 0;
    }

    º¯ÊýÃû: memcpy
    ¹¦ ÄÜ: ´ÓÔ´sourceÖп½±´n¸ö×Ö½Úµ½Ä¿±êdestinÖÐ
    ÓÃ ·¨: void *memcpy(void *destin, void *source, unsigned n);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char src[] = "******************************";
    char dest[] = "abcdefghijlkmnopqrstuvwxyz0123456709";
    char *ptr;
    printf("destination before memcpy: %s\n", dest);
    ptr = memcpy(dest, src, strlen(src));
    if (ptr)
    printf("destination after memcpy: %s\n", dest);
    else
    printf("memcpy failed\n");
    return 0;
    }


    º¯ÊýÃû: memicmp
    ¹¦ ÄÜ: ±È½ÏÁ½¸ö´®s1ºÍs2µÄÇ°n¸ö×Ö½Ú, ºöÂÔ´óСд
    ÓÃ ·¨: int memicmp(void *s1, void *s2, unsigned n);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char *buf1 = "ABCDE123";
    char *buf2 = "abcde456";
    int stat;
    stat = memicmp(buf1, buf2, 5);
    printf("The strings to position 5 are ");
    if (stat)
    printf("not ");
    printf("the same\n");
    return 0;
    }


    º¯ÊýÃû: memmove
    ¹¦ ÄÜ: Òƶ¯Ò»¿é×Ö½Ú
    ÓÃ ·¨: void *memmove(void *destin, void *source, unsigned n);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char *dest = "abcdefghijklmnopqrstuvwxyz0123456789";
    char *src = "******************************";
    printf("destination prior to memmove: %s\n", dest);
    memmove(dest, src, 26);
    printf("destination after memmove: %s\n", dest);
    return 0;
    }



    º¯ÊýÃû: memset
    ¹¦ ÄÜ: ÉèÖÃsÖеÄËùÓÐ×Ö½ÚΪch, sÊý×éµÄ´óСÓÉn¸ø¶¨
    ÓÃ ·¨: void *memset(void *s, char ch, unsigned n);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char buffer[] = "Hello world\n";
    printf("Buffer before memset: %s\n", buffer);
    memset(buffer, '*', strlen(buffer) - 1);
    printf("Buffer after memset: %s\n", buffer);
    return 0;
    }


    º¯ÊýÃû: mkdir
    ¹¦ ÄÜ: ½¨Á¢Ò»¸öĿ¼
    ÓÃ ·¨: int mkdir(char *pathname);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    int status;
    clrscr();
    status = mkdir("asdfjklm");
    (!status) ? (printf("Directory created\n")) :
    (printf("Unable to create directory\n"));
    getch();
    system("dir");
    getch();
    status = rmdir("asdfjklm");
    (!status) ? (printf("Directory deleted\n")) :
    (perror("Unable to delete directory"));
    return 0;
    }



    º¯ÊýÃû: mktemp
    ¹¦ ÄÜ: ½¨Á¢Î¨Ò»µÄÎļþÃû
    ÓÃ ·¨: char *mktemp(char *template);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    /* fname defines the template for the
    temporary file. */
    char *fname = "TXXXXXX", *ptr;
    ptr = mktemp(fname);
    printf("%s\n",ptr);
    return 0;
    }


    º¯ÊýÃû: MK_FP
    ¹¦ ÄÜ: ÉèÖÃÒ»¸öÔ¶Ö¸Õë
    ÓÃ ·¨: void far *MK_FP(unsigned seg, unsigned off);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    int gd, gm, i;
    unsigned int far *screen;
    detectgraph(&gd, &gm);
    if (gd == HERCMONO)
    screen = MK_FP(0xB000, 0);
    else
    screen = MK_FP(0xB800, 0);
    for (i=0; i<26; i++)
    screen[i] = 0x0700 + ('a' + i);
    return 0;
    }


    º¯ÊýÃû: modf
    ¹¦ ÄÜ: °ÑÊý·ÖΪָÊýºÍβÊý
    ÓÃ ·¨: double modf(double value, double *iptr);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    double fraction, integer;
    double number = 100000.567;
    fraction = modf(number, &integer);
    printf("The whole and fractional parts of %lf are %lf and %lf\n",
    number, integer, fraction);
    return 0;
    }


    º¯ÊýÃû: movedata
    ¹¦ ÄÜ: ¿½±´×Ö½Ú
    ÓÃ ·¨: void movedata(int segsrc, int offsrc, int segdest,
    int offdest, unsigned numbytes);
    ³ÌÐòÀý:
    #include ;
    #define MONO_BASE 0xB000
    /* saves the contents of the monochrome screen in buffer */
    void save_mono_screen(char near *buffer)
    {
    movedata(MONO_BASE, 0, _DS, (unsigned)buffer, 80*25*2);
    }
    int main(void)
    {
    char buf[80*25*2];
    save_mono_screen(buf);
    }


    º¯ÊýÃû: moverel
    ¹¦ ÄÜ: ½«µ±Ç°Î»ÖÃ(CP)Òƶ¯Ò»Ïà¶Ô¾àÀë
    ÓÃ ·¨: void far moverel(int dx, int dy);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    char msg[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    /* move the C.P. to location (20, 30) */
    moveto(20, 30);
    /* plot a pixel at the C.P. */
    putpixel(getx(), gety(), getmaxcolor());
    /* create and output a message at (20, 30) */
    sprintf(msg, " (%d, %d)", getx(), gety());
    outtextxy(20, 30, msg);
    /* move to a point a relative distance */
    /* away from the current value of C.P. */
    moverel(100, 100);
    /* plot a pixel at the C.P. */
    putpixel(getx(), gety(), getmaxcolor());
    /* create and output a message at C.P. */
    sprintf(msg, " (%d, %d)", getx(), gety());
    outtext(msg);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }


    º¯ÊýÃû: movetext
    ¹¦ ÄÜ: ½«ÆÁÄ»Îı¾´ÓÒ»¸ö¾ØÐÎÇøÓò¿½±´µ½ÁíÒ»¸ö¾ØÐÎÇøÓò
    ÓÃ ·¨: int movetext(int left, int top, int right, int bottom,
    int newleft, int newtop);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char *str = "This is a test string";
    clrscr();
    cputs(str);
    getch();
    movetext(1, 1, strlen(str), 2, 10, 10);
    getch();
    return 0;
    }


    º¯ÊýÃû: moveto
    ¹¦ ÄÜ: ½«CPÒƵ½(x, y)
    ÓÃ ·¨: void far moveto(int x, int y);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    char msg[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    /* move the C.P. to location (20, 30) */
    moveto(20, 30);
    /* plot a pixel at the C.P. */
    putpixel(getx(), gety(), getmaxcolor());
    /* create and output a message at (20, 30) */
    sprintf(msg, " (%d, %d)", getx(), gety());
    outtextxy(20, 30, msg);
    /* move to (100, 100) */
    moveto(100, 100);
    /* plot a pixel at the C.P. */
    putpixel(getx(), gety(), getmaxcolor());
    /* create and output a message at C.P. */
    sprintf(msg, " (%d, %d)", getx(), gety());
    outtext(msg);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }


    º¯ÊýÃû: movemem
    ¹¦ ÄÜ: Òƶ¯Ò»¿é×Ö½Ú
    ÓÃ ·¨: void movemem(void *source, void *destin, unsigned len);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char *source = "Borland International";
    char *destination;
    int length;
    length = strlen(source);
    destination = malloc(length + 1);
    movmem(source,destination,length);
    printf("%s\n",destination);
    return 0;
    }


    º¯ÊýÃû: normvideo
    ¹¦ ÄÜ: Ñ¡ÔñÕý³£ÁÁ¶È×Ö·û
    ÓÃ ·¨: void normvideo(void);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    normvideo();
    cprintf("NORMAL Intensity Text\r\n");
    return 0;
    }


    º¯ÊýÃû: nosound
    ¹¦ ÄÜ: ¹Ø±ÕPCÑïÉùÆ÷
    ÓÃ ·¨: void nosound(void);
    ³ÌÐòÀý:
    /* Emits a 7-Hz tone for 10 seconds.
    True story: 7 Hz is the resonant frequency of a chicken's skull cavity.
    This was determined empirically in Australia, where a new factory
    generating 7-Hz tones was located too close to a chicken ranch:
    When the factory started up, all the chickens died.
    Your PC may not be able to emit a 7-Hz tone.
    */
    int main(void)
    {
    sound(7);
    delay(10000);
    nosound();
    }

  8. hfh08 ÓÚ 2006-08-21 15:56:51·¢±í:

    º¯ÊýÃû: getmaxy
    ¹¦ ÄÜ: ·µ»ØÆÁÄ»µÄ×î´óy×ø±ê
    ÓÃ ·¨: int far getmaxy(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int midx, midy;
    char xrange[80], yrange[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* convert max resolution values into strings */
    sprintf(xrange, "X values range from 0..%d", getmaxx());
    sprintf(yrange, "Y values range from 0..%d", getmaxy());
    /* display the information */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(midx, midy, xrange);
    outtextxy(midx, midy+textheight("W"), yrange);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getmodename
    ¹¦ ÄÜ: ·µ»Øº¬ÓÐÖ¸¶¨Í¼ÐÎģʽÃûµÄ×Ö·û´®Ö¸Õë
    ÓÃ ·¨: char *far getmodename(int mode_name);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request autodetection */
    int gdriver = DETECT, gmode, errorcode;
    int midx, midy, mode;
    char numname[80], modename[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* get mode number and name strings */
    mode = getgraphmode();
    sprintf(numname, "%d is the current mode number.", mode);
    sprintf(modename, "%s is the current graphics mode.", getmodename(mode));
    /* display the information */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(midx, midy, numname);
    outtextxy(midx, midy+2*textheight("W"), modename);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getmoderange
    ¹¦ ÄÜ: È¡¸ø¶¨Í¼ÐÎÇý¶¯³ÌÐòµÄģʽ·¶Î§
    ÓÃ ·¨: void far getmoderange(int graphdriver, int far *lomode,
    int far *himode);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int midx, midy;
    int low, high;
    char mrange[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* get the mode range for this driver */
    getmoderange(gdriver, &low, &high);
    /* convert mode range info. into strings */
    sprintf(mrange, "This driver supports modes %d..%d", low, high);
    /* display the information */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(midx, midy, mrange);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getpalette
    ¹¦ ÄÜ: ·µ»ØÓйص±Ç°µ÷É«°åµÄÐÅÏ¢
    ÓÃ ·¨: void far getpalette(struct palettetype far *palette);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    struct palettetype pal;
    char psize[80], pval[20];
    int i, ht;
    int y = 10;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    /* an error occurred */
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n",
    grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    /* terminate with an error code */
    exit(1);
    }
    /* grab a copy of the palette */
    getpalette(&pal);
    /* convert palette info. into strings */
    sprintf(psize, "The palette has %d \
    modifiable entries.", pal.size);
    /* display the information */
    outtextxy(0, y, psize);
    if (pal.size != 0)
    {
    ht = textheight("W");
    y += 2*ht;
    outtextxy(0, y, "Here are the current \
    values:");
    y += 2*ht;
    for (i=0; i{
    sprintf(pval,
    "palette[%02d]: 0x%02X", i,
    outtextxy(0, y, pval);
    }
    }
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getpass
    ¹¦ ÄÜ: ¶ÁÒ»¸ö¿ÚÁî
    ÓÃ ·¨: char *getpass(char *prompt);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    char *password;
    password = getpass("Input a password:");
    cprintf("The password is: %s\r\n",
    password);
    return 0;
    }
    º¯ÊýÃû: getpixel
    ¹¦ ÄÜ: È¡µÃÖ¸¶¨ÏñËصÄÑÕÉ«
    ÓÃ ·¨: int far getpixel(int x, int y);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #include ;
    #define PIXEL_COUNT 1000
    #define DELAY_TIME 100 /* in milliseconds */
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int i, x, y, color, maxx, maxy,
    maxcolor, seed;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    /* an error occurred */
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n",
    grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    /* terminate with an error code */
    exit(1);
    }
    maxx = getmaxx() + 1;
    maxy = getmaxy() + 1;
    maxcolor = getmaxcolor() + 1;
    while (!kbhit())
    {
    /* seed the random number generator */
    seed = random(32767);
    srand(seed);
    for (i=0; i{
    x = random(maxx);
    y = random(maxy);
    color = random(maxcolor);
    putpixel(x, y, color);
    }
    delay(DELAY_TIME);
    srand(seed);
    for (i=0; i{
    x = random(maxx);
    y = random(maxy);
    color = random(maxcolor);
    if (color == getpixel?? ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;h;(;);;; ;e;t;p;s;p;(;););;; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;e;s;e;t; ;t;o; ;s;e;g;m;e;n;t; ;o;f; ;t;h;e; ;P;S;P; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;i;n;e; ;i;s; ;l;o;c;a;t;e;d; ;a;t; ;o;f;f;s;e;t; ;0;x;8;1; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;t; ;o;f; ;P;S;P; ; ; ; ; ; ; ; ;
    º¯ÊýÃû: gets
    ¹¦ ÄÜ: ´ÓÁ÷ÖÐÈ¡Ò»×Ö·û´®
    ÓÃ ·¨: char *gets(char *string);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    char string[80];
    printf("Input a string:");
    gets(string);
    printf("The string input was: %s\n",
    string);
    return 0;
    }
    º¯ÊýÃû: gettext
    ¹¦ ÄÜ: ½«Îı¾·½Ê½ÆÁÄ»ÉϵÄÎı¾¿½±´µ½´æ´¢Çø
    ÓÃ ·¨: int gettext(int left, int top, int right, int bottom, void *destin);
    ³ÌÐòÀý:
    #include ;
    char buffer[4096];
    int main(void)
    {
    int i;
    clrscr();
    for (i = 0; i <= 20; i++)
    cprintf("Line #%d\r\n", i);
    gettext(1, 1, 80, 25, buffer);
    gotoxy(1, 25);
    cprintf("Press any key to clear screen...");
    getch();
    clrscr();
    gotoxy(1, 25);
    cprintf("Press any key to restore screen...");
    getch();
    puttext(1, 1, 80, 25, buffer);
    gotoxy(1, 25);
    cprintf("Press any key to quit...");
    getch();
    return 0;
    }
    º¯ÊýÃû: gettextinfo
    ¹¦ ÄÜ: È¡µÃÎı¾Ä£Ê½µÄÏÔʾÐÅÏ¢
    ÓÃ ·¨: void gettextinfo(struct text_info *inforec);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    struct text_info ti;
    gettextinfo(&ti);
    cprintf("window left %2d\r\n",ti.winleft);
    cprintf("window top %2d\r\n",ti.wintop);
    cprintf("window right %2d\r\n",ti.winright);
    cprintf("window bottom %2d\r\n",ti.winbottom);
    cprintf("attribute %2d\r\n",ti.attribute);
    cprintf("normal attribute %2d\r\n",ti.normattr);
    cprintf("current mode %2d\r\n",ti.currmode);
    cprintf("screen height %2d\r\n",ti.screenheight);
    cprintf("screen width %2d\r\n",ti.screenwidth);
    cprintf("current x %2d\r\n",ti.curx);
    cprintf("current y %2d\r\n",ti.cury);
    return 0;
    }
    º¯ÊýÃû: gettextsettings
    ¹¦ ÄÜ: ·µ»ØÓйص±Ç°Í¼ÐÎÎı¾×ÖÌåµÄÐÅÏ¢
    ÓÃ ·¨: void far gettextsettings(struct textsettingstype far *textinfo);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    /* the names of the fonts supported */
    char *font[] = { "DEFAULT_FONT",
    "TRIPLEX_FONT",
    "SMALL_FONT",
    "SANS_SERIF_FONT",
    "GOTHIC_FONT"
    };
    /* the names of the text directions supported */
    char *dir[] = { "HORIZ_DIR", "VERT_DIR" };
    /* horizontal text justifications supported */
    char *hjust[] = { "LEFT_TEXT", "CENTER_TEXT", "RIGHT_TEXT" };
    /* vertical text justifications supported */
    char *vjust[] = { "BOTTOM_TEXT", "CENTER_TEXT", "TOP_TEXT" };
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    struct textsettingstype textinfo;
    int midx, midy, ht;
    char fontstr[80], dirstr[80], sizestr[80];
    char hjuststr[80], vjuststr[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* get information about current text settings */
    gettextsettings(&textinfo);
    /* convert text information into strings */
    sprintf(fontstr, "%s is the text style.", font[textinfo.font]);
    sprintf(dirstr, "%s is the text direction.", dir[textinfo.direction]);
    sprintf(sizestr, "%d is the text size.", textinfo.charsize);
    sprintf(hjuststr, "%s is the horizontal justification.",
    hjust[textinfo.horiz]);
    sprintf(vjuststr, "%s is the vertical justification.",
    vjust[textinfo.vert]);
    /* display the information */
    ht = textheight("W");
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(midx, midy, fontstr);
    outtextxy(midx, midy+2*ht, dirstr);
    outtextxy(midx, midy+4*ht, sizestr);
    outtextxy(midx, midy+6*ht, hjuststr);
    outtextxy(midx, midy+8*ht, vjuststr);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: gettime
    ¹¦ ÄÜ: È¡µÃϵͳʱ¼ä
    ÓÃ ·¨: void gettime(struct time *timep);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    struct time t;
    gettime(&t);
    printf("The current time is: %2d:%02d:%02d.%02d\n",
    t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
    return 0;
    }
    º¯ÊýÃû: getvect
    ¹¦ ÄÜ: È¡µÃÖжÏÏòÁ¿Èë¿Ú
    ÓÃ ·¨: void interrupt(*getvect(int intr_num));
    ³ÌÐòÀý:
    #include ;
    #include ;
    void interrupt get_out(); /* interrupt prototype */
    void interrupt (*oldfunc)(); /* interrupt function pointer */
    int looping = 1;
    int main(void)
    {
    puts("Press ;; to terminate");
    /* save the old interrupt */
    oldfunc = getvect(5);
    /* install interrupt handler */
    setvect(5,get_out);
    /* do nothing */
    while (looping);
    /* restore to original interrupt routine */
    setvect(5,oldfunc);
    puts("Success");
    return 0;
    }
    void interrupt get_out()
    {
    looping = 0; /* change global variable to get out of loop */
    }
    º¯ÊýÃû: getverify
    ¹¦ ÄÜ: ·µ»ØDOSУÑé±ê־״̬
    ÓÃ ·¨: int getverify(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    if (getverify())
    printf("DOS verify flag is on\n");
    else
    printf("DOS verify flag is off\n");
    return 0;
    }
    º¯ÊýÃû: getviewsetting
    ¹¦ ÄÜ: ·µ»ØÓйص±Ç°ÊÓÇøµÄÐÅÏ¢
    ÓÃ ·¨: void far getviewsettings(struct viewporttype far *viewport);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    char *clip[] = { "OFF", "ON" };
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    struct viewporttype viewinfo;
    int midx, midy, ht;
    char topstr[80], botstr[80], clipstr[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* get information about current viewport */
    getviewsettings(&viewinfo);
    /* convert text information into strings */
    sprintf(topstr, "(%d, %d) is the upper left viewport corner.",
    viewinfo.left, viewinfo.top);
    sprintf(botstr, "(%d, %d) is the lower right viewport corner.",
    viewinfo.right, viewinfo.bottom);
    sprintf(clipstr, "Clipping is turned %s.", clip[viewinfo.clip]);
    /* display the information */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    ht = textheight("W");
    outtextxy(midx, midy, topstr);
    outtextxy(midx, midy+2*ht, botstr);
    outtextxy(midx, midy+4*ht, clipstr);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getw
    ¹¦ ÄÜ: ´ÓÁ÷ÖÐÈ¡Ò»ÕûÊý
    ÓÃ ·¨: int getw(FILE *strem);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #define FNAME "test.$$$"
    int main(void)
    {
    FILE *fp;
    int word;
    /* place the word in a file */
    fp = fopen(FNAME, "wb");
    if (fp == NULL)
    {
    printf("Error opening file %s\n", FNAME);
    exit(1);
    }
    word = 94;
    putw(word,fp);
    if (ferror(fp))
    printf("Error writing to file\n");
    else
    printf("Successful write\n");
    fclose(fp);
    /* reopen the file */
    fp = fopen(FNAME, "rb");
    if (fp == NULL)
    {
    printf("Error opening file %s\n", FNAME);
    exit(1);
    }
    /* extract the word */
    word = getw(fp);
    if (ferror(fp))
    printf("Error reading file\n");
    else
    printf("Successful read: word = %d\n", word);
    /* clean up */
    fclose(fp);
    unlink(FNAME);
    return 0;
    }
    º¯ÊýÃû: getx
    ¹¦ ÄÜ: ·µ»Øµ±Ç°Í¼ÐÎλÖõÄx×ø±ê
    ÓÃ ·¨: int far getx(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    char msg[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    /* move to the screen center point */
    moveto(getmaxx() / 2, getmaxy() / 2);
    /* create a message string */
    sprintf(msg, "<-(%d, %d) is the here.", getx(), gety());
    /* display the message */
    outtext(msg);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: gety
    ¹¦ ÄÜ: ·µ»Øµ±Ç°Í¼ÐÎλÖõÄy×ø±ê
    ÓÃ ·¨: int far gety(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    char msg[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    /* move to the screen center point */
    moveto(getmaxx() / 2, getmaxy() / 2);
    /* create a message string */
    sprintf(msg, "<-(%d, %d) is the here.", getx(), gety());
    /* display the message */
    outtext(msg);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: gmtime
    ¹¦ ÄÜ: °ÑÈÕÆÚºÍʱ¼äת»»Îª¸ñÁÖÄáÖαê׼ʱ¼ä(GMT)
    ÓÃ ·¨: struct tm *gmtime(long *clock);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    /* Pacific Standard Time & Daylight Savings */
    char *tzstr = "TZ=PST8PDT";
    int main(void)
    {
    time_t t;
    struct tm *gmt, *area;
    putenv(tzstr);
    tzset();
    t = time(NULL);
    area = localtime(&t);
    printf("Local time is: %s", asctime(area));
    gmt = gmtime(&t);
    printf("GMT is: %s", asctime(gmt));
    return 0;
    }
    º¯ÊýÃû: gotoxy
    ¹¦ ÄÜ: ÔÚÎı¾´°¿ÚÖÐÉèÖùâ±ê
    ÓÃ ·¨: void gotoxy(int x, int y);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    clrscr();
    gotoxy(35, 12);
    cprintf("Hello world");
    getch();
    return 0;
    }
    º¯ÊýÃû: gotoxy
    ¹¦ ÄÜ: ÔÚÎı¾´°¿ÚÖÐÉèÖùâ±ê
    ÓÃ ·¨: void gotoxy(int x, int y);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    clrscr();
    gotoxy(35, 12);
    cprintf("Hello world");
    getch();
    return 0;
    }
    º¯ÊýÃû: graphdefaults
    ¹¦ ÄÜ: ½«ËùÓÐͼÐÎÉèÖø´Î»ÎªËüÃǵÄȱʡֵ
    ÓÃ ·¨: void far graphdefaults(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int maxx, maxy;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "c:\\bor\\Borland\\bgi");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    maxx = getmaxx();
    maxy = getmaxy();
    /* output line with non-default settings */
    setlinestyle(DOTTED_LINE, 0, 3);
    line(0, 0, maxx, maxy);
    outtextxy(maxx/2, maxy/3, "Before default values are restored.");
    getch();
    /* restore default values for everything */
    graphdefaults();
    /* clear the screen */
    cleardevice();
    /* output line with default settings */
    line(0, 0, maxx, maxy);
    outtextxy(maxx/2, maxy/3, "After restoring default values.");
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: grapherrormsg
    ¹¦ ÄÜ: ·µ»ØÒ»¸ö´íÎóÐÅÏ¢´®µÄÖ¸Õë
    ÓÃ ·¨: char *far grapherrormsg(int errorcode);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #define NONSENSE -50
    int main(void)
    {
    /* FORCE AN ERROR TO OCCUR */
    int gdriver = NONSENSE, gmode, errorcode;
    /* initialize graphics mode */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    /* if an error occurred, then output a */
    /* descriptive error message. */
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    /* draw a line */
    line(0, 0, getmaxx(), getmaxy());
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: graphresult
    ¹¦ ÄÜ: ·µ»Ø×îºóÒ»´Î²»³É¹¦µÄͼÐβÙ×÷µÄ´íÎó´úÂë
    ÓÃ ·¨: int far graphresult(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    /* draw a line */
    line(0, 0, getmaxx(), getmaxy());
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: _graphfreemem
    ¹¦ ÄÜ: Óû§¿ÉÐ޸ĵÄͼÐδ洢ÇøÊͷź¯Êý
    ÓÃ ·¨: void far _graphfreemem(void far *ptr, unsigned size);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int midx, midy;
    /* clear the text screen */
    clrscr();
    printf("Press any key to initialize graphics mode:");
    getch();
    clrscr();
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* display a message */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(midx, midy, "Press any key to exit graphics mode:");
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    /* called by the graphics kernel to allocate memory */
    void far * far _graphgetmem(unsigned size)
    {
    printf("_graphgetmem called to allocate %d bytes.\n", size);
    printf("hit any key:");
    getch();
    printf("\n");
    /* allocate memory from far heap */
    return farmalloc(size);
    }
    /* called by the graphics kernel to free memory */
    void far _graphfreemem(void far *ptr, unsigned size)
    {
    printf("_graphfreemem called to free %d bytes.\n", size);
    printf("hit any key:");
    getch();
    printf("\n");
    /* free ptr from far heap */
    farfree(ptr);
    }

  9. hfh08 ÓÚ 2006-08-21 15:56:20·¢±í:

    º¯ÊýÃû: exp
    ¹¦ ÄÜ: Ö¸Êýº¯Êý
    ÓÃ ·¨: double exp(double x);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    double result;
    double x = 4.0;
    result = exp(x);
    printf("'e' raised to the power \
    of %lf (e ^ %lf) = %lf\n",
    x, x, result);
    return 0;
    }
    º¯ÊýÃû: fabs
    ¹¦ ÄÜ: ·µ»Ø¸¡µãÊýµÄ¾ø¶ÔÖµ
    ÓÃ ·¨: double fabs(double x);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    float number = -1234.0;
    printf("number: %f absolute value: %f\n",
    number, fabs(number));
    return 0;
    }
    º¯ÊýÃû: farcalloc
    ¹¦ ÄÜ: ´ÓÔ¶¶ÑÕ»ÖÐÉêÇë¿Õ¼ä
    ÓÃ ·¨: void far *farcalloc(unsigned long units, unsigned ling unitsz);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char far *fptr;
    char *str = "Hello";
    /* allocate memory for the far pointer */
    fptr = farcalloc(10, sizeof(char));
    /* copy "Hello" into allocated memory */
    /*
    Note: movedata is used because you
    might be in a small data model, in
    which case a normal string copy routine
    can not be used since it assumes the
    pointer size is near.
    */
    movedata(FP_SEG(str), FP_OFF(str),
    FP_SEG(fptr), FP_OFF(fptr),
    strlen(str));
    /* display string (note the F modifier) */
    printf("Far string is: %Fs\n", fptr);
    /* free the memory */
    farfree(fptr);
    return 0;
    }
    º¯ÊýÃû: farcoreleft
    ¹¦ ÄÜ: ·µ»ØÔ¶¶ÑÖÐδ×÷Óô洢Çø´óС
    ÓÃ ·¨: long farcoreleft(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    printf("The difference between the\
    highest allocated block in the\
    far\n");
    printf("heap and the top of the far heap\
    is: %lu bytes\n", farcoreleft());
    return 0;
    }
    º¯ÊýÃû: farfree
    ¹¦ ÄÜ: ´ÓÔ¶¶ÑÖÐÊÍ·ÅÒ»¿é
    ÓÃ ·¨: void farfree(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char far *fptr;
    char *str = "Hello";
    /* allocate memory for the far pointer */
    fptr = farcalloc(10, sizeof(char));
    /* copy "Hello" into allocated memory */
    /*
    Note: movedata is used because you might be in a small data model,
    in which case a normal string copy routine can't be used since it
    assumes the pointer size is near.
    */
    movedata(FP_SEG(str), FP_OFF(str),
    FP_SEG(fptr), FP_OFF(fptr),
    strlen(str));
    /* display string (note the F modifier) */
    printf("Far string is: %Fs\n", fptr);
    /* free the memory */
    farfree(fptr);
    return 0;
    }
    º¯ÊýÃû: farmalloc
    ¹¦ ÄÜ: ´ÓÔ¶¶ÑÖзÖÅä´æ´¢¿é
    ÓÃ ·¨: void far *farmalloc(unsigned long size);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char far *fptr;
    char *str = "Hello";
    /* allocate memory for the far pointer */
    fptr = farmalloc(10);
    /* copy "Hello" into allocated memory */
    /*
    Note: movedata is used because we might
    be in a small data model, in which case
    a normal string copy routine can not be
    used since it assumes the pointer size
    is near.
    */
    movedata(FP_SEG(str), FP_OFF(str),
    FP_SEG(fptr), FP_OFF(fptr),
    strlen(str));
    /* display string (note the F modifier) */
    printf("Far string is: %Fs\n", fptr);
    /* free the memory */
    farfree(fptr);
    return 0;
    }
    º¯ÊýÃû: farrealloc
    ¹¦ ÄÜ: µ÷ÕûÔ¶¶ÑÖеķÖÅä¿é
    ÓÃ ·¨: void far *farrealloc(void far *block, unsigned long newsize);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char far *fptr;
    fptr = farmalloc(10);
    printf("First address: %Fp\n", fptr);
    fptr = farrealloc(fptr,20);
    printf("New address : %Fp\n", fptr);
    farfree(fptr);
    return 0;
    }
    º¯ÊýÃû: fclose
    ¹¦ ÄÜ: ¹Ø±ÕÒ»¸öÁ÷
    ÓÃ ·¨: int fclose(FILE *stream);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    FILE *fp;
    char buf[11] = "0123456789";
    /* create a file containing 10 bytes */
    fp = fopen("DUMMY.FIL", "w");
    fwrite(&buf, strlen(buf), 1, fp);
    /* close the file */
    fclose(fp);
    return 0;
    }
    º¯ÊýÃû: fcloseall
    ¹¦ ÄÜ: ¹Ø±Õ´ò¿ªÁ÷
    ÓÃ ·¨: int fcloseall(void);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    int streams_closed;
    /* open two streams */
    fopen("DUMMY.ONE", "w");
    fopen("DUMMY.TWO", "w");
    /* close the open streams */
    streams_closed = fcloseall();
    if (streams_closed == EOF)
    /* issue an error message */
    perror("Error");
    else
    /* print result of fcloseall() function */
    printf("%d streams were closed.\n", streams_closed);
    return 0;
    }
    º¯ÊýÃû: fcvt
    ¹¦ ÄÜ: °ÑÒ»¸ö¸¡µãÊýת»»Îª×Ö·û´®
    ÓÃ ·¨: char *fcvt(double value, int ndigit, int *decpt, int *sign);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char *string;
    double value;
    int dec, sign;
    int ndig = 10;
    clrscr();
    value = 9.876;
    string = ecvt(value, ndig, &dec, &sign);
    printf("string = %s dec = %d \
    sign = %d\n", string, dec, sign);
    value = -123.45;
    ndig= 15;
    string = ecvt(value,ndig,&dec,&sign);
    printf("string = %s dec = %d sign = %d\n",
    string, dec, sign);
    value = 0.6789e5; /* scientific
    notation */
    ndig = 5;
    string = ecvt(value,ndig,&dec,&sign);
    printf("string = %s dec = %d\
    sign = %d\n", string, dec, sign);
    return 0;
    }
    º¯ÊýÃû: fdopen
    ¹¦ ÄÜ: °ÑÁ÷ÓëÒ»¸öÎļþ¾ä±úÏà½Ó
    ÓÃ ·¨: FILE *fdopen(int handle, char *type);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    int handle;
    FILE *stream;
    /* open a file */
    handle = open("DUMMY.FIL", O_CREAT,
    S_IREAD | S_IWRITE);
    /* now turn the handle into a stream */
    stream = fdopen(handle, "w");
    if (stream == NULL)
    printf("fdopen failed\n");
    else
    {
    fprintf(stream, "Hello world\n");
    fclose(stream);
    }
    return 0;
    }
    º¯ÊýÃû: feof
    ¹¦ ÄÜ: ¼ì²âÁ÷ÉϵÄÎļþ½áÊø·û
    ÓÃ ·¨: int feof(FILE *stream);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    FILE *stream;
    /* open a file for reading */
    stream = fopen("DUMMY.FIL", "r");
    /* read a character from the file */
    fgetc(stream);
    /* check for EOF */
    if (feof(stream))
    printf("We have reached end-of-file\n");
    /* close the file */
    fclose(stream);
    return 0;
    }
    º¯ÊýÃû: ferror
    ¹¦ ÄÜ: ¼ì²âÁ÷ÉϵĴíÎó
    ÓÃ ·¨: int ferror(FILE *stream);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    FILE *stream;
    /* open a file for writing */
    stream = fopen("DUMMY.FIL", "w");
    /* force an error condition by attempting to read */
    (void) getc(stream);
    if (ferror(stream)) /* test for an error on the stream */
    {
    /* display an error message */
    printf("Error reading from DUMMY.FIL\n");
    /* reset the error and EOF indicators */
    clearerr(stream);
    }
    fclose(stream);
    return 0;
    }
    º¯ÊýÃû: fflush
    ¹¦ ÄÜ: Çå³ýÒ»¸öÁ÷
    ÓÃ ·¨: int fflush(FILE *stream);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    void flush(FILE *stream);
    int main(void)
    {
    FILE *stream;
    char msg[] = "This is a test";
    /* create a file */
    stream = fopen("DUMMY.FIL", "w");
    /* write some data to the file */
    fwrite(msg, strlen(msg), 1, stream);
    clrscr();
    printf("Press any key to flush\
    DUMMY.FIL:");
    getch();
    /* flush the data to DUMMY.FIL without\
    closing it */
    flush(stream);
    printf("\nFile was flushed, Press any key\
    to quit:");
    getch();
    return 0;
    }
    void flush(FILE *stream)
    {
    int duphandle;
    /* flush the stream's internal buffer */
    fflush(stream);
    /* make a duplicate file handle */
    duphandle = dup(fileno(stream));
    /* close the duplicate handle to flush\
    the DOS buffer */
    close(duphandle);
    }
    º¯ÊýÃû: fgetc
    ¹¦ ÄÜ: ´ÓÁ÷ÖжÁÈ¡×Ö·û
    ÓÃ ·¨: int fgetc(FILE *stream);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    FILE *stream;
    char string[] = "This is a test";
    char ch;
    /* open a file for update */
    stream = fopen("DUMMY.FIL", "w+");
    /* write a string into the file */
    fwrite(string, strlen(string), 1, stream);
    /* seek to the beginning of the file */
    fseek(stream, 0, SEEK_SET);
    do
    {
    /* read a char from the file */
    ch = fgetc(stream);
    /* display the character */
    putch(ch);
    } while (ch != EOF);
    fclose(stream);
    return 0;
    }
    º¯ÊýÃû: fgetchar
    ¹¦ ÄÜ: ´ÓÁ÷ÖжÁÈ¡×Ö·û
    ÓÃ ·¨: int fgetchar(void);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    char ch;
    /* prompt the user for input */
    printf("Enter a character followed by \
    ;: ");
    /* read the character from stdin */
    ch = fgetchar();
    /* display what was read */
    printf("The character read is: '%c'\n",
    ch);
    return 0;
    }
    º¯ÊýÃû: fgetpos
    ¹¦ ÄÜ: È¡µÃµ±Ç°ÎļþµÄ¾ä±ú
    ÓÃ ·¨: int fgetpos(FILE *stream);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    FILE *stream;
    char string[] = "This is a test";
    fpos_t filepos;
    /* open a file for update */
    stream = fopen("DUMMY.FIL", "w+");
    /* write a string into the file */
    fwrite(string, strlen(string), 1, stream);
    /* report the file pointer position */
    fgetpos(stream, &filepos);
    printf("The file pointer is at byte\
    %ld\n", filepos);
    fclose(stream);
    return 0;
    }
    º¯ÊýÃû: fgets
    ¹¦ ÄÜ: ´ÓÁ÷ÖжÁÈ¡Ò»×Ö·û´®
    ÓÃ ·¨: char *fgets(char *string, int n, FILE *stream);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    FILE *stream;
    char string[] = "This is a test";
    char msg[20];
    /* open a file for update */
    stream = fopen("DUMMY.FIL", "w+");
    /* write a string into the file */
    fwrite(string, strlen(string), 1, stream);
    /* seek to the start of the file */
    fseek(stream, 0, SEEK_SET);
    /* read a string from the file */
    fgets(msg, strlen(string)+1, stream);
    /* display the string */
    printf("%s", msg);
    fclose(stream);
    return 0;
    }
    º¯ÊýÃû: filelength
    ¹¦ ÄÜ: È¡Îļþ³¤¶È×Ö½ÚÊý
    ÓÃ ·¨: long filelength(int handle);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    int handle;
    char buf[11] = "0123456789";
    /* create a file containing 10 bytes */
    handle = open("DUMMY.FIL", O_CREAT);
    write(handle, buf, strlen(buf));
    /* display the size of the file */
    printf("file length in bytes: %ld\n",
    filelength(handle));
    /* close the file */
    close(handle);
    return 0;
    }
    º¯ÊýÃû: fillellipse
    ¹¦ ÄÜ: »­³ö²¢Ìî³äÒ»ÍÖÔ²
    ÓÃ ·¨: void far fillellipse(int x, int y, int xradius, int yradius);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    int gdriver = DETECT, gmode;
    int xcenter, ycenter, i;
    initgraph(&gdriver,&gmode,"");
    xcenter = getmaxx() / 2;
    ycenter = getmaxy() / 2;
    for (i=0; i<13; i++)
    {
    setfillstyle(i,WHITE);
    fillellipse(xcenter,ycenter,100,50);
    getch();
    }
    closegraph();
    return 0;
    }
    º¯ÊýÃû: fillpoly
    ¹¦ ÄÜ: »­²¢Ìî³äÒ»¸ö¶à±ßÐÎ
    ÓÃ ·¨: void far fillpoly(int numpoints, int far *polypoints);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int i, maxx, maxy;
    /* our polygon array */
    int poly[8];
    /* initialize graphics, local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk)
    /* an error occurred */
    {
    printf("Graphics error: %s\n",
    grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1);
    /* terminate with an error code */
    }
    maxx = getmaxx();
    maxy = getmaxy();
    poly[0] = 20; /* 1st vertext */
    poly[1] = maxy / 2;
    poly[2] = maxx - 20; /* 2nd */
    poly[3] = 20;
    poly[4] = maxx - 50; /* 3rd */
    poly[5] = maxy - 20;
    /*
    4th vertex. fillpoly automatically
    closes the polygon.
    */
    poly[6] = maxx / 2;
    poly[7] = maxy / 2;
    /* loop through the fill patterns */
    for (i=EMPTY_FILL; i{
    /* set fill pattern */
    setfillstyle(i, getmaxcolor());
    /* draw a filled polygon */
    fillpoly(4, poly);
    getch();
    }
    /* clean up */
    closegraph();
    return 0;
    }
    º¯ÊýÃû: findfirst, findnext
    ¹¦ ÄÜ: ËÑË÷´ÅÅÌĿ¼; È¡µÃÏÂÒ»¸öÆ¥ÅäµÄfindfirstģʽµÄÎļþ
    ÓÃ ·¨: int findfirst(char *pathname, struct ffblk *ffblk, int attrib);
    int findnext(struct ffblk *ffblk);
    ³ÌÐòÀý:
    /* findnext example */
    #include ;
    #include ;
    int main(void)
    {
    struct ffblk ffblk;
    int done;
    printf("Directory listing of *.*\n");
    done = findfirst("*.*",&ffblk,0);
    while (!done)
    {
    printf(" %s\n", ffblk.ff_name);
    done = findnext(&ffblk);
    }
    return 0;
    }
    º¯ÊýÃû: floodfill
    ¹¦ ÄÜ: Ìî³äÒ»¸öÓнçÇøÓò
    ÓÃ ·¨: void far floodfill(int x, int y, int border);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int maxx, maxy;
    /* initialize graphics, local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk)
    /* an error occurred */
    {
    printf("Graphics error: %s\n",
    grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1);
    /* terminate with an error code */
    }
    maxx = getmaxx();
    maxy = getmaxy();
    /* select drawing color */
    setcolor(getmaxcolor());
    /* select fill color */
    setfillstyle(SOLID_FILL, getmaxcolor());
    /* draw a border around the screen */
    rectangle(0, 0, maxx, maxy);
    /* draw some circles */
    circle(maxx / 3, maxy /2, 50);
    circle(maxx / 2, 20, 100);
    circle(maxx-20, maxy-50, 75);
    circle(20, maxy-20, 25);
    /* wait for a key */
    getch();
    /* fill in bounded region */
    floodfill(2, 2, getmaxcolor());
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: floor
    ¹¦ ÄÜ: ÏòÏÂÉáÈë
    ÓÃ ·¨: double floor(double x);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    double number = 123.54;
    double down, up;
    down = floor(number);
    up = ceil(number);
    printf("original number %10.2lf\n",
    number);
    printf("number rounded down %10.2lf\n",
    down);
    printf("number rounded up %10.2lf\n",
    up);
    return 0;
    }
    º¯ÊýÃû: flushall
    ¹¦ ÄÜ: Çå³ýËùÓлº³åÇø
    ÓÃ ·¨: int flushall(void);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    FILE *stream;
    /* create a file */
    stream = fopen("DUMMY.FIL", "w");
    /* flush all open streams */
    printf("%d streams were flushed.\n",
    flushall());
    /* close the file */
    fclose(stream);
    return 0;
    }
    º¯ÊýÃû: fmod
    ¹¦ ÄÜ: ¼ÆËãx¶ÔyµÄÄ£, ¼´x/yµÄÓàÊý
    ÓÃ ·¨: double fmod(double x, double y);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    double x = 5.0, y = 2.0;
    double result;
    result = fmod(x,y);
    printf("The remainder of (%lf / %lf) is \
    %lf\n", x, y, result);
    return 0;
    }
    º¯ÊýÃû: fnmerge
    ¹¦ ÄÜ: ½¨Á¢ÐÂÎļþÃû
    ÓÃ ·¨: void fnerge(char *path, char *drive, char *dir);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char s[MAXPATH];
    char drive[MAXDRIVE];
    char dir[MAXDIR];
    char file[MAXFILE];
    char ext[MAXEXT];
    getcwd(s,MAXPATH); /* get the current working directory */
    strcat(s,"\\"); /* append on a trailing \ character */
    fnsplit(s,drive,dir,file,ext); /* split the string to separate elems */
    strcpy(file,"DATA");
    strcpy(ext,".TXT");
    fnmerge(s,drive,dir,file,ext); /* merge everything into one string */
    puts(s); /* display resulting string */
    return 0;
    }
    º¯ÊýÃû: fopen
    ¹¦ ÄÜ: ´ò¿ªÒ»¸öÁ÷
    ÓÃ ·¨: FILE *fopen(char *filename, char *type);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char *s;
    char drive[MAXDRIVE];
    char dir[MAXDIR];
    char file[MAXFILE];
    char ext[MAXEXT];
    int flags;
    s=getenv("COMSPEC"); /* get the comspec environment parameter */
    flags=fnsplit(s,drive,dir,file,ext);
    printf("Command processor info:\n");
    if(flags & DRIVE)
    printf("\tdrive: %s\n",drive);
    if(flags & DIRECTORY)
    printf("\tdirectory: %s\n",dir);
    if(flags & FILENAME)
    printf("\tfile: %s\n",file);
    if(flags & EXTENSION)
    printf("\textension: %s\n",ext);
    return 0;
    }
    º¯ÊýÃû: fprintf
    ¹¦ ÄÜ: ´«Ë͸ñʽ»¯Êä³öµ½Ò»¸öÁ÷ÖÐ
    ÓÃ ·¨: int fprintf(FILE *stream, char *format[, argument,...]);
    ³ÌÐòÀý:
    /* Program to create backup of the
    AUTOEXEC.BAT file */
    #include ;
    int main(void)
    {
    FILE *in, *out;
    if ((in = fopen("\\AUTOEXEC.BAT", "rt"))
    == NULL)
    {
    fprintf(stderr, "Cannot open input \
    file.\n");
    return 1;
    }
    if ((out = fopen("\\AUTOEXEC.BAK", "wt"))
    == NULL)
    {
    fprintf(stderr, "Cannot open output \
    file.\n");
    return 1;
    }
    while (!feof(in))
    fputc(fgetc(in), out);
    fclose(in);
    fclose(out);
    return 0;
    }
    º¯ÊýÃû: FP_OFF
    ¹¦ ÄÜ: »ñÈ¡Ô¶µØÖ·Æ«ÒÆÁ¿
    ÓÃ ·¨: unsigned FP_OFF(void far *farptr);
    ³ÌÐòÀý:
    /* FP_OFF */
    #include ;
    #include ;
    int main(void)
    {
    char *str = "fpoff.c";
    printf("The offset of this file in memory\
    is: %Fp\n", FP_OFF(str));
    return 0;
    }
    º¯ÊýÃû: FP_SEG
    ¹¦ ÄÜ: »ñÈ¡Ô¶µØÖ·¶ÎÖµ
    ÓÃ ·¨: unsigned FP_SEG(void far *farptr);
    ³ÌÐòÀý:
    /* FP_SEG */
    #include ;
    #include ;
    int main(void)
    {
    char *filename = "fpseg.c";
    printf("The offset of this file in memory\
    is: %Fp\n", FP_SEG(filename));
    return(0);
    }
    º¯ÊýÃû: fputc
    ¹¦ ÄÜ: ËÍÒ»¸ö×Ö·ûµ½Ò»¸öÁ÷ÖÐ
    ÓÃ ·¨: int fputc(int ch, FILE *stream);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    char msg[] = "Hello world";
    int i = 0;
    while (msg[i])
    {
    fputc(msg[i], stdout);
    i++;
    }
    return 0;
    }
    º¯ÊýÃû: fputchar
    ¹¦ ÄÜ: ËÍÒ»¸ö×Ö·ûµ½±ê×¼Êä³öÁ÷(stdout)ÖÐ
    ÓÃ ·¨: int fputchar(char ch);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    char msg[] = "This is a test";
    int i = 0;
    while (msg[i])
    {
    fputchar(msg[i]);
    i++;
    }
    return 0;
    }
    º¯ÊýÃû: fputs
    ¹¦ ÄÜ: ËÍÒ»¸ö×Ö·ûµ½Ò»¸öÁ÷ÖÐ
    ÓÃ ·¨: int fputs(char *string, FILE *stream);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    /* write a string to standard output */
    fputs("Hello world\n", stdout);
    return 0;
    }
    º¯ÊýÃû: fread
    ¹¦ ÄÜ: ´ÓÒ»¸öÁ÷ÖжÁÊý¾Ý
    ÓÃ ·¨: int fread(void *ptr, int size, int nitems, FILE *stream);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    FILE *stream;
    char msg[] = "this is a test";
    char buf[20];
    if ((stream = fopen("DUMMY.FIL", "w+"))
    == NULL)
    {
    fprintf(stderr,
    "Cannot open output file.\n");
    return 1;
    }
    /* write some data to the file */
    fwrite(msg, strlen(msg)+1, 1, stream);
    /* seek to the beginning of the file */
    fseek(stream, SEEK_SET, 0);
    /* read the data and display it */
    fread(buf, strlen(msg)+1, 1, stream);
    printf("%s\n", buf);
    fclose(stream);
    return 0;
    }
    º¯ÊýÃû: free
    ¹¦ ÄÜ: ÊÍ·ÅÒÑ·ÖÅäµÄ¿é
    ÓÃ ·¨: void free(void *ptr);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    char *str;
    /* allocate memory for string */
    str = malloc(10);
    /* copy "Hello" to string */
    strcpy(str, "Hello");
    /* display string */
    printf("String is %s\n", str);
    /* free memory */
    free(str);
    return 0;
    }
    º¯ÊýÃû: freemem
    ¹¦ ÄÜ: ÊÍ·ÅÏÈÇ°·ÖÅäµÄDOSÄÚ´æ¿é
    ÓÃ ·¨: int freemem(unsigned seg);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    unsigned int size, segp;
    int stat;
    size = 64; /* (64 x 16) = 1024 bytes */
    stat = allocmem(size, &segp);
    if (stat < 0)
    printf("Allocated memory at segment:\
    %x\n", segp);
    else
    printf("Failed: maximum number of\
    paragraphs available is %u\n",
    stat);
    freemem(segp);
    return 0;
    }
    º¯ÊýÃû: freopen
    ¹¦ ÄÜ: Ìæ»»Ò»¸öÁ÷
    ÓÃ ·¨: FILE *freopen(char *filename, char *type, FILE *stream);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    /* redirect standard output to a file */
    if (freopen("OUTPUT.FIL", "w", stdout)
    == NULL)
    fprintf(stderr, "error redirecting\
    stdout\n");
    /* this output will go to a file */
    printf("This will go into a file.");
    /* close the standard output stream */
    fclose(stdout);
    return 0;
    }
    º¯ÊýÃû: frexp
    ¹¦ ÄÜ: °ÑÒ»¸öË«¾«¶ÈÊý·Ö½âΪβÊýµÄÖ¸Êý
    ÓÃ ·¨: double frexp(double value, int *eptr);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    double mantissa, number;
    int exponent;
    number = 8.0;
    mantissa = frexp(number, &exponent);
    printf("The number %lf is ", number);
    printf("%lf times two to the ", mantissa);
    printf("power of %d\n", exponent);
    return 0;
    }
    º¯ÊýÃû: fscanf
    ¹¦ ÄÜ: ´ÓÒ»¸öÁ÷ÖÐÖ´Ðиñʽ»¯ÊäÈë
    ÓÃ ·¨: int fscanf(FILE *stream, char *format[,argument...]);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    int i;
    printf("Input an integer: ");
    /* read an integer from the
    standard input stream */
    if (fscanf(stdin, "%d", &i))
    printf("The integer read was: %i\n",
    i);
    else
    {
    fprintf(stderr, "Error reading an \
    integer from stdin.\n");
    exit(1);
    }
    return 0;
    }
    º¯ÊýÃû: fseek
    ¹¦ ÄÜ: Öض¨Î»Á÷ÉϵÄÎļþÖ¸Õë
    ÓÃ ·¨: int fseek(FILE *stream, long offset, int fromwhere);
    ³ÌÐòÀý:
    #include ;
    long filesize(FILE *stream);
    int main(void)
    {
    FILE *stream;
    stream = fopen("MYFILE.TXT", "w+");
    fprintf(stream, "This is a test");
    printf("Filesize of MYFILE.TXT is %ld bytes\n", filesize(stream));
    fclose(stream);
    return 0;
    }
    long filesize(FILE *stream)
    {
    long curpos, length;
    curpos = ftell(stream);
    fseek(stream, 0L, SEEK_END);
    length = ftell(stream);
    fseek(stream, curpos, SEEK_SET);
    return length;
    }
    º¯ÊýÃû: fsetpos
    ¹¦ ÄÜ: ¶¨Î»Á÷ÉϵÄÎļþÖ¸Õë
    ÓÃ ·¨: int fsetpos(FILE *stream, const fpos_t *pos);
    ³ÌÐòÀý:
    #include ;
    #include ;
    void showpos(FILE *stream);
    int main(void)
    {
    FILE *stream;
    fpos_t filepos;
    /* open a file for update */
    stream = fopen("DUMMY.FIL", "w+");
    /* save the file pointer position */
    fgetpos(stream, &filepos);
    /* write some data to the file */
    fprintf(stream, "This is a test");
    /* show the current file position */
    showpos(stream);
    /* set a new file position, display it */
    if (fsetpos(stream, &filepos) == 0)
    showpos(stream);
    else
    {
    fprintf(stderr, "Error setting file \
    pointer.\n");
    exit(1);
    }
    /* close the file */
    fclose(stream);
    return 0;
    }
    void showpos(FILE *stream)
    {
    fpos_t pos;
    /* display the current file pointer
    position of a stream */
    fgetpos(stream, &pos);
    printf("File position: %ld\n", pos);
    }
    º¯ÊýÃû: fstat
    ¹¦ ÄÜ: »ñÈ¡´ò¿ªÎļþÐÅÏ¢
    ÓÃ ·¨: int fstat(char *handle, struct stat *buff);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    struct stat statbuf;
    FILE *stream;
    /* open a file for update */
    if ((stream = fopen("DUMMY.FIL", "w+"))
    == NULL)
    {
    fprintf(stderr, "Cannot open output \
    file.\n");
    return(1);
    }
    fprintf(stream, "This is a test");
    fflush(stream);
    /* get information about the file */
    fstat(fileno(stream), &statbuf);
    fclose(stream);
    /* display the information returned */
    if (statbuf.st_mode & S_IFCHR)
    printf("Handle refers to a device.\n");
    if (statbuf.st_mode & S_IFREG)
    printf("Handle refers to an ordinary \
    file.\n");
    if (statbuf.st_mode & S_IREAD)
    printf("User has read permission on \
    file.\n");
    if (statbuf.st_mode & S_IWRITE)
    printf("User has write permission on \
    file.\n");
    printf("Drive letter of file: %c\n",
    'A'+statbuf.st_dev);
    printf("Size of file in bytes: %ld\n",
    statbuf.st_size);
    printf("Time file last opened: %s\n",
    ctime(&statbuf.st_ctime));
    return 0;
    }
    º¯ÊýÃû: ftell
    ¹¦ ÄÜ: ·µ»Øµ±Ç°ÎļþÖ¸Õë
    ÓÃ ·¨: long ftell(FILE *stream);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    FILE *stream;
    stream = fopen("MYFILE.TXT", "w+");
    fprintf(stream, "This is a test");
    printf("The file pointer is at byte \
    %ld\n", ftell(stream));
    fclose(stream);
    return 0;
    }
    º¯ÊýÃû: fwrite
    ¹¦ ÄÜ: дÄÚÈݵ½Á÷ÖÐ
    ÓÃ ·¨: int fwrite(void *ptr, int size, int nitems, FILE *stream);
    ³ÌÐòÀý:
    #include ;
    struct mystruct
    {
    int i;
    char ch;
    };
    int main(void)
    {
    FILE *stream;
    struct mystruct s;
    if ((stream = fopen("TEST.$$$", "wb")) == NULL) /* open file TEST.$$$ */
    {
    fprintf(stderr, "Cannot open output file.\n");
    return 1;
    }
    s.i = 0;
    s.ch = 'A';
    fwrite(&s, sizeof(s), 1, stream); /* write struct s to file */
    fclose(stream); /* close file */
    return 0;
    }
    º¯ÊýÃû: gcvt
    ¹¦ ÄÜ: °Ñ¸¡µãÊýת»»³É×Ö·û´®
    ÓÃ ·¨: char *gcvt(double value, int ndigit, char *buf);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char str[25];
    double num;
    int sig = 5; /* significant digits */
    /* a regular number */
    num = 9.876;
    gcvt(num, sig, str);
    printf("string = %s\n", str);
    /* a negative number */
    num = -123.4567;
    gcvt(num, sig, str);
    printf("string = %s\n", str);
    /* scientific notation */
    num = 0.678e5;
    gcvt(num, sig, str);
    printf("string = %s\n", str);
    return(0);
    }
    º¯ÊýÃû: geninterrupt
    ¹¦ ÄÜ: ²úÉúÒ»¸öÈíÖжÏ
    ÓÃ ·¨: void geninterrupt(int intr_num);
    ³ÌÐòÀý:
    #include ;
    #include ;
    /* function prototype */
    void writechar(char ch);
    int main(void)
    {
    clrscr();
    gotoxy(80,25);
    writechar('*');
    getch();
    return 0;
    }
    /*
    outputs a character at the current cursor
    position using the video BIOS to avoid the
    scrolling of the screen when writing to
    location (80,25).
    */
    void writechar(char ch)
    {
    struct text_info ti;
    /* grab current text settings */
    gettextinfo(&ti);
    /* interrupt 0x10 sub-function 9 */
    _AH = 9;
    /* character to be output */
    _AL = ch;
    _BH = 0; /* video page */
    _BL = ti.attribute; /* video attribute */
    _CX = 1; /* repetition factor */
    geninterrupt(0x10); /* output the char */
    }
    º¯ÊýÃû: getarccoords
    ¹¦ ÄÜ: È¡µÃ×îºóÒ»´Îµ÷ÓÃarcµÄ×ø±ê
    ÓÃ ·¨: void far getarccoords(struct arccoordstype far *arccoords);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    struct arccoordstype arcinfo;
    int midx, midy;
    int stangle = 45, endangle = 270;
    char sstr[80], estr[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    /* an error occurred */
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n",
    grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    /* terminate with an error code */
    exit(1);
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* draw arc and get coordinates */
    setcolor(getmaxcolor());
    arc(midx, midy, stangle, endangle, 100);
    getarccoords(&arcinfo);
    /* convert arc information into strings */
    sprintf(sstr, "*- (%d, %d)",
    arcinfo.xstart, arcinfo.ystart);
    sprintf(estr, "*- (%d, %d)",
    arcinfo.xend, arcinfo.yend);
    /* output the arc information */
    outtextxy(arcinfo.xstart,
    arcinfo.ystart, sstr);
    outtextxy(arcinfo.xend,
    arcinfo.yend, estr);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getaspectratio
    ¹¦ ÄÜ: ·µ»Øµ±Ç°Í¼ÐÎģʽµÄ×ݺá±È
    ÓÃ ·¨: void far getaspectratio(int far *xasp, int far *yasp);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int xasp, yasp, midx, midy;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    /* an error occurred */
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n",
    grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    /* terminate with an error code */
    exit(1);
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    setcolor(getmaxcolor());
    /* get current aspect ratio settings */
    getaspectratio(&xasp, &yasp);
    /* draw normal circle */
    circle(midx, midy, 100);
    getch();
    /* draw wide circle */
    cleardevice();
    setaspectratio(xasp/2, yasp);
    circle(midx, midy, 100);
    getch();
    /* draw narrow circle */
    cleardevice();
    setaspectratio(xasp, yasp/2);
    circle(midx, midy, 100);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getbkcolor
    ¹¦ ÄÜ: ·µ»Øµ±Ç°±³¾°ÑÕÉ«
    ÓÃ ·¨: int far getbkcolor(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int bkcolor, midx, midy;
    char bkname[35];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    /* an error occurred */
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n",
    grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    /* terminate with an error code */
    exit(1);
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    setcolor(getmaxcolor());
    /* for centering text on the display */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    /* get the current background color */
    bkcolor = getbkcolor();
    /* convert color value into a string */
    itoa(bkcolor, bkname, 10);
    strcat(bkname,
    " is the current background color.");
    /* display a message */
    outtextxy(midx, midy, bkname);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getc
    ¹¦ ÄÜ: ´ÓÁ÷ÖÐÈ¡×Ö·û
    ÓÃ ·¨: int getc(FILE *stream);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    char ch;
    printf("Input a character:");
    /* read a character from the
    standard input stream */
    ch = getc(stdin);
    printf("The character input was: '%c'\n",
    ch);
    return 0;
    }
    º¯ÊýÃû: getcbrk
    ¹¦ ÄÜ: »ñÈ¡Control_breakÉèÖÃ
    ÓÃ ·¨: int getcbrk(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    if (getcbrk())
    printf("Cntrl-brk flag is on\n");
    else
    printf("Cntrl-brk flag is off\n");
    return 0;
    }
    º¯ÊýÃû: getch
    ¹¦ ÄÜ: ´Ó¿ØÖÆ̨ÎÞ»ØÏÔµØÈ¡Ò»¸ö×Ö·û
    ÓÃ ·¨: int getch(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char ch;
    printf("Input a character:");
    ch = getche();
    printf("\nYou input a '%c'\n", ch);
    return 0;
    }
    º¯ÊýÃû: getchar
    ¹¦ ÄÜ: ´ÓstdinÁ÷ÖжÁ×Ö·û
    ÓÃ ·¨: int getchar(void);
    ³ÌÐòÀý:
    #include ;
    int main(void)
    {
    int c;
    /* Note that getchar reads from stdin and
    is line buffered; this means it will
    not return until you press ENTER. */
    while ((c = getchar()) != '\n')
    printf("%c", c);
    return 0;
    }
    º¯ÊýÃû: getche
    ¹¦ ÄÜ: ´Ó¿ØÖÆ̨ȡ×Ö·û(´ø»ØÏÔ)
    ÓÃ ·¨: int getche(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char ch;
    printf("Input a character:");
    ch = getche();
    printf("\nYou input a '%c'\n", ch);
    return 0;
    }
    º¯ÊýÃû: getcolor
    ¹¦ ÄÜ: ·µ»Øµ±Ç°»­ÏßÑÕÉ«
    ÓÃ ·¨: int far getcolor(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int color, midx, midy;
    char colname[35];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    /* an error occurred */
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n",
    grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    /* terminate with an error code */
    exit(1);
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    setcolor(getmaxcolor());
    /* for centering text on the display */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    /* get the current drawing color */
    color = getcolor();
    /* convert color value into a string */
    itoa(color, colname, 10);
    strcat(colname,
    " is the current drawing color.");
    /* display a message */
    outtextxy(midx, midy, colname);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getcurdir
    ¹¦ ÄÜ: È¡Ö¸¶¨Çý¶¯Æ÷µÄµ±Ç°Ä¿Â¼
    ÓÃ ·¨: int getcurdir(int drive, char *direc);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    char *current_directory(char *path)
    {
    strcpy(path, "X:\\"); /* fill string with form of response: X:\ */
    path[0] = 'A' + getdisk(); /* replace X with current drive letter */
    getcurdir(0, path+3); /* fill rest of string with current directory */
    return(path);
    }
    int main(void)
    {
    char curdir[MAXPATH];
    current_directory(curdir);
    printf("The current directory is %s\n", curdir);
    return 0;
    }
    º¯ÊýÃû: getcwd
    ¹¦ ÄÜ: È¡µ±Ç°¹¤×÷Ŀ¼
    ÓÃ ·¨: char *getcwd(char *buf, int n);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char buffer[MAXPATH];
    getcwd(buffer, MAXPATH);
    printf("The current directory is: %s\n", buffer);
    return 0;
    }
    º¯ÊýÃû: getdate
    ¹¦ ÄÜ: È¡DOSÈÕÆÚ
    ÓÃ ·¨: void getdate(struct *dateblk);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    struct date d;
    getdate(&d);
    printf("The current year is: %d\n",
    d.da_year);
    printf("The current day is: %d\n",
    d.da_day);
    printf("The current month is: %d\n",
    d.da_mon);
    return 0;
    }
    º¯ÊýÃû: getdefaultpalette
    ¹¦ ÄÜ: ·µ»Øµ÷É«°å¶¨Òå½á¹¹
    ÓÃ ·¨: struct palettetype *far getdefaultpalette(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int i;
    /* structure for returning palette copy */
    struct palettetype far *pal=(void *) 0;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    /* an error occurred */
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n",
    grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    /* terminate with an error code */
    exit(1);
    }
    setcolor(getmaxcolor());
    /* return a pointer to the default palette */
    pal = getdefaultpalette();
    for (i=0; i<16; i++)
    {
    printf("colors[%d] = %d\n", i,
    pal->;colors[i]);
    getch();
    }
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getdisk
    ¹¦ ÄÜ: È¡µ±Ç°´ÅÅÌÇý¶¯Æ÷ºÅ
    ÓÃ ·¨: int getdisk(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    int disk;
    disk = getdisk() + 'A';
    printf("The current drive is: %c\n",
    disk);
    return 0;
    }
    º¯ÊýÃû: getdrivername
    ¹¦ ÄÜ: ·µ»ØÖ¸Ïò°üº¬µ±Ç°Í¼ÐÎÇý¶¯³ÌÐòÃû×ÖµÄ×Ö·û´®Ö¸Õë
    ÓÃ ·¨: char *getdrivename(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    /* stores the device driver name */
    char *drivername;
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    /* an error occurred */
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n",
    grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    /* terminate with an error code */
    exit(1);
    }
    setcolor(getmaxcolor());
    /* get name of the device driver in use */
    drivername = getdrivername();
    /* for centering text on the screen */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    /* output the name of the driver */
    outtextxy(getmaxx() / 2, getmaxy() / 2,
    drivername);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getdta
    ¹¦ ÄÜ: È¡´ÅÅÌ´«ÊäµØÖ·
    ÓÃ ·¨: char far *getdta(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char far *dta;
    dta = getdta();
    printf("The current disk transfer \
    address is: %Fp\n", dta);
    return 0;
    }
    º¯ÊýÃû: getenv
    ¹¦ ÄÜ: ´Ó»·¾³ÖÐÈ¡×Ö·û´®
    ÓÃ ·¨: char *getenv(char *envvar);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    char *s;
    s=getenv("COMSPEC"); /* get the comspec environment parameter */
    printf("Command processor: %s\n",s); /* display comspec parameter */
    return 0;
    }
    º¯ÊýÃû: getfat, getfatd
    ¹¦ ÄÜ: È¡Îļþ·ÖÅä±íÐÅÏ¢
    ÓÃ ·¨: void getfat(int drive, struct fatinfo *fatblkp);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    struct fatinfo diskinfo;
    int flag = 0;
    printf("Please insert disk in drive A\n");
    getchar();
    getfat(1, &diskinfo);
    /* get drive information */
    printf("\nDrive A: is ");
    switch((unsigned char) diskinfo.fi_fatid)
    {
    case 0xFD:
    printf("360K low density\n");
    break;
    case 0xF9:
    printf("1.2 Meg high density\n");
    break;
    default:
    printf("unformatted\n");
    flag = 1;
    }
    if (!flag)
    {
    printf(" sectors per cluster %5d\n",
    diskinfo.fi_sclus);
    printf(" number of clusters %5d\n",
    diskinfo.fi_nclus);
    printf(" bytes per sector %5d\n",
    diskinfo.fi_bysec);
    }
    return 0;
    }
    º¯ÊýÃû: getfillpattern
    ¹¦ ÄÜ: ½«Óû§¶¨ÒåµÄÌî³äģʽ¿½±´µ½ÄÚ´æÖÐ
    ÓÃ ·¨: void far getfillpattern(char far *upattern);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int maxx, maxy;
    char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x25, 0x27, 0x04, 0x04};
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    maxx = getmaxx();
    maxy = getmaxy();
    setcolor(getmaxcolor());
    /* select a user defined fill pattern */
    setfillpattern(pattern, getmaxcolor());
    /* fill the screen with the pattern */
    bar(0, 0, maxx, maxy);
    getch();
    /* get the current user defined fill pattern */
    getfillpattern(pattern);
    /* alter the pattern we grabbed */
    pattern[4] -= 1;
    pattern[5] -= 3;
    pattern[6] += 3;
    pattern[7] -= 4;
    /* select our new pattern */
    setfillpattern(pattern, getmaxcolor());
    /* fill the screen with the new pattern */
    bar(0, 0, maxx, maxy);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getfillsettings
    ¹¦ ÄÜ: È¡µÃÓйص±Ç°Ìî³äģʽºÍÌî³äÑÕÉ«µÄÐÅÏ¢
    ÓÃ ·¨: void far getfillsettings(struct fillsettingstype far *fillinfo);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    / the names of the fill styles supported */
    char *fname[] = { "EMPTY_FILL",
    "SOLID_FILL",
    "LINE_FILL",
    "LTSLASH_FILL",
    "SLASH_FILL",
    "BKSLASH_FILL",
    "LTBKSLASH_FILL",
    "HATCH_FILL",
    "XHATCH_FILL",
    "INTERLEAVE_FILL",
    "WIDE_DOT_FILL",
    "CLOSE_DOT_FILL",
    "USER_FILL"
    };
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    struct fillsettingstype fillinfo;
    int midx, midy;
    char patstr[40], colstr[40];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* get information about current fill pattern and color */
    getfillsettings(&fillinfo);
    /* convert fill information into strings */
    sprintf(patstr, "%s is the fill style.", fname[fillinfo.pattern]);
    /* display the information */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(midx, midy, patstr);
    outtextxy(midx, midy+2*textheight("W"), colstr);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getftime
    ¹¦ ÄÜ: È¡ÎļþÈÕÆÚºÍʱ¼ä
    ÓÃ ·¨: int getftime(int handle, struct ftime *ftimep);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    FILE *stream;
    struct ftime ft;
    if ((stream = fopen("TEST.$$$",
    "wt")) == NULL)
    {
    fprintf(stderr,
    "Cannot open output file.\n");
    return 1;
    }
    getftime(fileno(stream), &ft);
    printf("File time: %u:%u:%u\n",
    ft.ft_hour, ft.ft_min,
    ft.ft_tsec * 2);
    printf("File date: %u/%u/%u\n",
    ft.ft_month, ft.ft_day,
    ft.ft_year+1980);
    fclose(stream);
    return 0;
    }
    º¯ÊýÃû: getgraphmode
    ¹¦ ÄÜ: ·µ»Øµ±Ç°Í¼ÐÎģʽ
    ÓÃ ·¨: int far getgraphmode(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int midx, midy, mode;
    char numname[80], modename[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    /* an error occurred */
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n",
    grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    /* terminate with an error code */
    exit(1);
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* get mode number and name strings */
    mode = getgraphmode();
    sprintf(numname,
    "%d is the current mode number.",
    mode);
    sprintf(modename,
    "%s is the current graphics mode",
    getmodename(mode));
    /* display the information */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(midx, midy, numname);
    outtextxy(midx, midy+2*textheight("W"),
    modename);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getftime
    ¹¦ ÄÜ: È¡ÎļþÈÕÆÚºÍʱ¼ä
    ÓÃ ·¨: int getftime(int handle, struct ftime *ftimep);
    ³ÌÐòÀý:
    #include ;
    #include ;
    int main(void)
    {
    FILE *stream;
    struct ftime ft;
    if ((stream = fopen("TEST.$$$",
    "wt")) == NULL)
    {
    fprintf(stderr,
    "Cannot open output file.\n");
    return 1;
    }
    getftime(fileno(stream), &ft);
    printf("File time: %u:%u:%u\n",
    ft.ft_hour, ft.ft_min,
    ft.ft_tsec * 2);
    printf("File date: %u/%u/%u\n",
    ft.ft_month, ft.ft_day,
    ft.ft_year+1980);
    fclose(stream);
    return 0;
    }
    º¯ÊýÃû: getgraphmode
    ¹¦ ÄÜ: ·µ»Øµ±Ç°Í¼ÐÎģʽ
    ÓÃ ·¨: int far getgraphmode(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int midx, midy, mode;
    char numname[80], modename[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    /* an error occurred */
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n",
    grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    /* terminate with an error code */
    exit(1);
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* get mode number and name strings */
    mode = getgraphmode();
    sprintf(numname,
    "%d is the current mode number.",
    mode);
    sprintf(modename,
    "%s is the current graphics mode",
    getmodename(mode));
    /* display the information */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(midx, midy, numname);
    outtextxy(midx, midy+2*textheight("W"),
    modename);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getimage
    ¹¦ ÄÜ: ½«Ö¸¶¨ÇøÓòµÄÒ»¸öλͼ´æµ½Ö÷´æÖÐ
    ÓÃ ·¨: void far getimage(int left, int top, int right, int bottom,
    void far *bitmap);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    #include ;
    void save_screen(void far *buf[4]);
    void restore_screen(void far *buf[4]);
    int maxx, maxy;
    int main(void)
    {
    int gdriver=DETECT, gmode, errorcode;
    void far *ptr[4];
    /* auto-detect the graphics driver and mode */
    initgraph(&gdriver, &gmode, "");
    errorcode = graphresult(); /* check for any errors */
    if (errorcode != grOk)
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1);
    }
    maxx = getmaxx();
    maxy = getmaxy();
    /* draw an image on the screen */
    rectangle(0, 0, maxx, maxy);
    line(0, 0, maxx, maxy);
    line(0, maxy, maxx, 0);
    save_screen(ptr); /* save the current screen */
    getch(); /* pause screen */
    cleardevice(); /* clear screen */
    restore_screen(ptr); /* restore the screen */
    getch(); /* pause screen */
    closegraph();
    return 0;
    }
    void save_screen(void far *buf[4])
    {
    unsigned size;
    int ystart=0, yend, yincr, block;
    yincr = (maxy+1) / 4;
    yend = yincr;
    size = imagesize(0, ystart, maxx, yend); /* get byte size of image */
    for (block=0; block<=3; block++)
    {
    if ((buf[block] = farmalloc(size)) == NULL)
    {
    closegraph();
    printf("Error: not enough heap space in save_screen().\n");
    exit(1);
    }
    getimage(0, ystart, maxx, yend, buf[block]);
    ystart = yend + 1;
    yend += yincr + 1;
    }
    }
    void save_screen(void far *buf[4])
    {
    unsigned size;
    int ystart=0, yend, yincr, block;
    yincr = (maxy+1) / 4;
    yend = yincr;
    size = imagesize(0, ystart, maxx, yend); /* get byte size of image */
    for (block=0; block<=3; block++)
    {
    if ((buf[block] = farmalloc(size)) == NULL)
    {
    closegraph();
    printf("Error: not enough heap space in save_screen().\n");
    exit(1);
    }
    getimage(0, ystart, maxx, yend, buf[block]);
    ystart = yend + 1;
    yend += yincr + 1;
    }
    }
    void restore_screen(void far *buf[4])
    {
    int ystart=0, yend, yincr, block;
    yincr = (maxy+1) / 4;
    yend = yincr;
    for (block=0; block<=3; block++)
    {
    putimage(0, ystart, buf[block], COPY_PUT);
    farfree(buf[block]);
    ystart = yend + 1;
    yend += yincr + 1;
    }
    }
    º¯ÊýÃû: getlinesettings
    ¹¦ ÄÜ: È¡µ±Ç°ÏßÐÍ¡¢Ä£Ê½ºÍ¿í¶È
    ÓÃ ·¨: void far getlinesettings(struct linesettingstype far *lininfo):
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    /* the names of the line styles supported */
    char *lname[] = { "SOLID_LINE",
    "DOTTED_LINE",
    "CENTER_LINE",
    "DASHED_LINE",
    "USERBIT_LINE"
    };
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    struct linesettingstype lineinfo;
    int midx, midy;
    char lstyle[80], lpattern[80], lwidth[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* get information about current line settings */
    getlinesettings(&lineinfo);
    /* convert line information into strings */
    sprintf(lstyle, "%s is the line style.",
    lname[lineinfo.linestyle]);
    sprintf(lpattern, "0x%X is the user-defined line pattern.",
    lineinfo.upattern);
    sprintf(lwidth, "%d is the line thickness.",
    lineinfo.thickness);
    /* display the information */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(midx, midy, lstyle);
    outtextxy(midx, midy+2*textheight("W"), lpattern);
    outtextxy(midx, midy+4*textheight("W"), lwidth);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getmaxcolor
    ¹¦ ÄÜ: ·µ»Ø¿ÉÒÔ´«¸øº¯ÊýsetcolorµÄ×î´óÑÕÉ«Öµ
    ÓÃ ·¨: int far getmaxcolor(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int midx, midy;
    char colstr[80];
    /* initialize graphics and local variables
    */ initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* grab the color info. and convert it to a string */
    sprintf(colstr, "This mode supports colors 0..%d", getmaxcolor());
    /* display the information */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(midx, midy, colstr);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }
    º¯ÊýÃû: getmaxx
    ¹¦ ÄÜ: ·µ»ØÆÁÄ»µÄ×î´óx×ø±ê
    ÓÃ ·¨: int far getmaxx(void);
    ³ÌÐòÀý:
    #include ;
    #include ;
    #include ;
    #include ;
    int main(void)
    {
    /* request auto detection */
    int gdriver = DETECT, gmode, errorcode;
    int midx, midy;
    char xrange[80], yrange[80];
    /* initialize graphics and local variables */
    initgraph(&gdriver, &gmode, "");
    /* read result of initialization */
    errorcode = graphresult();
    if (errorcode != grOk) /* an error occurred */
    {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    printf("Press any key to halt:");
    getch();
    exit(1); /* terminate with an error code */
    }
    midx = getmaxx() / 2;
    midy = getmaxy() / 2;
    /* convert max resolution values into strings */
    sprintf(xrange, "X values range from 0..%d", getmaxx());
    sprintf(yrange, "Y values range from 0..%d", getmaxy());
    /* display the information */
    settextjustify(CENTER_TEXT, CENTER_TEXT);
    outtextxy(midx, midy, xrange);
    outtextxy(midx, midy+textheight("W"), yrange);
    /* clean up */
    getch();
    closegraph();
    return 0;
    }