哪位大哥可以把c,c++所有的库函数的作用给我解释一下!
c吧
全部回复
仅看楼主
level 1
比如#include
调用那些函数的时候需要先定义库函数呢?谢谢了!
2005年05月16日 02点05分 1
level 0
ytg
2005年07月05日 07点07分 2
level 0
作者: lovepanhong 2005-5-16 10:31   回复此发言 -------------------------------------------------------------------------------- 2 回复:哪位大哥可以把c,c++所有的库函数的作用给我解释一下! ytg 作者: 61.50.142.* 2005-7-5 15:40   回复此发言 -------------------------------------------------------------------------------- 本主题共有帖数 2 篇 标 题: 内 容: 图片链接: (如何贴图?) 用户名: 您目前是匿名发表 登录| 注册 (百度贴吧协议)
2005年07月05日 07点07分 3
level 0
作者: lovepanhong 2005-5-16 10:31   回复此发言 -------------------------------------------------------------------------------- 2 回复:哪位大哥可以把c,c++所有的库函数的作用给我解释一下! ytg 作者: lovepanhong 2005-5-16 10:31   回复此发言 -------------------------------------------------------------------------------- 2 回复:哪位大哥可以把c,c++所有的库函数的作用给我解释一下! ytg 作者: 61.50.142.* 2005-7-5 15:40   回复此发言 -------------------------------------------------------------------------------- 本主题共有帖数 2 篇 标 题: 内 容: 图片链接: (如何贴图?) 用户名: 您目前是匿名发表 登录| 注册 (百度贴吧协议) 作者: 61.50.142.* 2005-7-5 15:40   回复此发言 -------------------------------------------------------------------------------- 本主题共有帖数 2 篇 标 题: 内 容: 图片链接: (如何贴图?) 用户名: 您目前是匿名发表 登录| 注册 (百度贴吧协议)
2005年07月05日 07点07分 4
level 0
作者: lovepanhong 2005-5-16 10:31   回复此发言 -------------------------------------------------------------------------------- 2 回复:哪位大哥可以把c,c++所有的库函数的作用给我解释一下! ytg 作者: 61.50.142.* 2005-7-5 15:40   回复此发言 -------------------------------------------------------------------------------- 本主题共有帖数 2 篇 标 题: 内 容: 图片链接: (如何贴图?) 用户名: 您目前是匿名发表 登录| 注册 (百度贴吧协议)
2005年07月05日 07点07分 5
level 0
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(); 
2005年12月19日 17点12分 9
level 0
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; }
2005年12月19日 17点12分 10
level 0
C语言函数大全(c开头) 作者:unknown 更新时间: 2005-05-09 函数名: 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); 
2005年12月19日 17点12分 11
level 0
} 函数名: 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 
2005年12月19日 17点12分 12
level 0
#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"); 
2005年12月19日 17点12分 13
level 0
C语言函数大全(d开头) 作者:unknown 更新时间: 2005-05-09 函数名: 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(); 
2005年12月19日 17点12分 16
level 0
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; i printf("[%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; } C语言函数大全(f开头) 作者:unknown 更新时间: 2005-05-09 double fabs(double x); 返回双精度x的绝对值。 void far *farcalloc(unsigned long nunits,unsigned long unitsz); 堆中给含有nu从远nits个元素的,每个元素占用unitsz个字节长的数组分配存贮区。 成功是返回指向新分配的内存块的指针;若存贮空间不够,返回NULL。 unsigned long farcoreleft(void); 返回远堆中未用存贮区的大小。 void farfree(void far *block); 释放远堆中以前所分配内存块。 void far *farmalloc(unsigned long nbytes); 从远堆分配长nbytes字节的内存块,返回新地址。 void far *farrealloc(void far *oldblock,unsigned long nbytes); 调整已分配的内存块的大小为nbytes。需要的话,可把块中的内容复制到新位置。要注意:所有的可用的RAM可被分配,大于64K的块可被分配。 远指针用于存取被分配的块。返回重新分配的内存块的地址。若存贮块重新分配失败,返回NULL。 struct fcb { char fcb_drive; /* 0 = default, 1 = A, 2 = B */ char fcb_name[8]; /* File name */ char fcb_ext[3]; /* File extension */ short fcb_curblk; /* Current block number */ short fcb_recsize; /* Logical record size in bytes */ long fcb_filsize; /* File size in bytes */ short fcb_date; /* Date file was last written */ char fcb_resv[10]; /* Reserved for DOS */ 
2005年12月19日 17点12分 19
level 0
} 函数名: 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)); 
2005年12月19日 17点12分 24
level 0
/* 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)); 
2005年12月19日 17点12分 26
level 0
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]); sprintf(colstr, "%d is the fill color.", fillinfo.color); /* 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.", 
2005年12月19日 17点12分 28
level 0
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) 
2005年12月19日 17点12分 30
level 0
{ /* 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; } 函数名: 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 功 能: 返回含有指定图形模式名的字符串指针 
2005年12月19日 17点12分 31
level 0
用 法: 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 */ 
2005年12月19日 17点12分 32
level 0
[鬼脸]
2009年12月08日 05点12分 35
1