📄 s2.htm
字号:
<td align=center><table border="0" width="700" cellspacing="0" cellpadding="0" align=center><tr><td valign=top><font color=#cccccc>
<br>函数名: sbrk
<br>功 能: 改变数据段空间位置
<br>用 法: char *sbrk(int incr);
<br>程序例:
<br>
<br>#include <stdio.h>
<br>#include <alloc.h>
<br>
<br>int main(void)
<br>{
<br> printf("Changing allocation with sbrk()\n");
<br> printf("Before sbrk() call: %lu bytes free\n",
<br> (unsigned long) coreleft());
<br> sbrk(1000);
<br> printf(" After sbrk() call: %lu bytes free\n",
<br> (unsigned long) coreleft());
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: scanf
<br>功 能: 执行格式化输入
<br>用 法: int scanf(char *format[,argument,...]);
<br>程序例:
<br>
<br>#include <stdio.h>
<br>#include <conio.h>
<br>
<br>int main(void)
<br>{
<br> char label[20];
<br> char name[20];
<br> int entries = 0;
<br> int loop, age;
<br> double salary;
<br>
<br> struct Entry_struct
<br> {
<br> char name[20];
<br> int age;
<br> float salary;
<br> } entry[20];
<br>
<br>/* Input a label as a string of characters restricting to 20 characters */
<br> printf("\n\nPlease enter a label for the chart: ");
<br> scanf("%20s", label);
<br> fflush(stdin); /* flush the input stream in case of bad input */
<br>
<br>/* Input number of entries as an integer */
<br> printf("How many entries will there be? (less than 20) ");
<br> scanf("%d", &entries);
<br> fflush(stdin); /* flush the input stream in case of bad input */
<br>
<br>/* input a name restricting input to only letters upper or lower case */
<br> for (loop=0;loop<entries;++loop)
<br> {
<br> printf("Entry %d\n", loop);
<br> printf(" Name : ");
<br> scanf("%[A-Za-z]", entry[loop].name);
<br> fflush(stdin); /* flush the input stream in case of bad input */
<br>
<br>/* input an age as an integer */
<br> printf(" Age : ");
<br> scanf("%d", &entry[loop].age);
<br> fflush(stdin); /* flush the input stream in case of bad input */
<br>
<br>/* input a salary as a float */
<br> printf(" Salary : ");
<br> scanf("%f", &entry[loop].salary);
<br> fflush(stdin); /* flush the input stream in case of bad input */
<br> }
<br>
<br>/* Input a name, age and salary as a string, integer, and double */
<br> printf("\nPlease enter your name, age and salary\n");
<br> scanf("%20s %d %lf", name, &age, &salary);
<br>
<br>
<br>/* Print out the data that was input */
<br> printf("\n\nTable %s\n",label);
<br> printf("Compiled by %s age %d $%15.2lf\n", name, age, salary);
<br> printf("-----------------------------------------------------\n");
<br> for (loop=0;loop<entries;++loop)
<br> printf("%4d | %-20s | %5d | %15.2lf\n",
<br> loop + 1,
<br> entry[loop].name,
<br> entry[loop].age,
<br> entry[loop].salary);
<br> printf("-----------------------------------------------------\n");
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: searchpath
<br>功 能: 搜索DOS路径
<br>用 法: char *searchpath(char *filename);
<br>程序例:
<br>
<br>#include <stdio.h>
<br>#include <dir.h>
<br>
<br>int main(void)
<br>{
<br> char *p;
<br>
<br> /* Looks for TLINK and returns a pointer
<br> to the path */
<br> p = searchpath("TLINK.EXE");
<br> printf("Search for TLINK.EXE : %s\n", p);
<br>
<br> /* Looks for non-existent file */
<br> p = searchpath("NOTEXIST.FIL");
<br> printf("Search for NOTEXIST.FIL : %s\n", p);
<br>
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: sector
<br>功 能: 画并填充椭圆扇区
<br>用 法: void far sector(int x, int y, int stangle, int endangle);
<br>程序例:
<br>
<br>#include <graphics.h>
<br>#include <stdlib.h>
<br>#include <stdio.h>
<br>#include <conio.h>
<br>
<br>int main(void)
<br>{
<br> /* request auto detection */
<br> int gdriver = DETECT, gmode, errorcode;
<br> int midx, midy, i;
<br> int stangle = 45, endangle = 135;
<br> int xrad = 100, yrad = 50;
<br>
<br> /* initialize graphics and local variables */
<br> initgraph(&gdriver, &gmode, "");
<br>
<br> /* read result of initialization */
<br> errorcode = graphresult();
<br> if (errorcode != grOk) /* an error occurred */
<br> {
<br> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<br> printf("Press any key to halt:");
<br> getch();
<br> exit(1); /* terminate with an error code */
<br> }
<br>
<br> midx = getmaxx() / 2;
<br> midy = getmaxy() / 2;
<br>
<br> /* loop through the fill patterns */
<br> for (i=EMPTY_FILL; i<USER_FILL; i++)
<br> {
<br> /* set the fill style */
<br> setfillstyle(i, getmaxcolor());
<br>
<br> /* draw the sector slice */
<br> sector(midx, midy, stangle, endangle, xrad, yrad);
<br>
<br> getch();
<br> }
<br>
<br> /* clean up */
<br> closegraph();
<br> return 0;
<br>}
<br>
<br>
<br>函数名: segread
<br>功 能: 读段寄存器值
<br>用 法: void segread(struct SREGS *segtbl);
<br>程序例:
<br>
<br>#include <stdio.h>
<br>#include <dos.h>
<br>
<br>int main(void)
<br>{
<br> struct SREGS segs;
<br>
<br> segread(&segs);
<br> printf("Current segment register settings\n\n");
<br> printf("CS: %X DS: %X\n", segs.cs, segs.ds);
<br> printf("ES: %X SS: %X\n", segs.es, segs.ss);
<br>
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: setactivepage
<br>功 能: 设置图形输出活动页
<br>用 法: void far setactivepage(int pagenum);
<br>程序例:
<br>
<br>#include <graphics.h>
<br>#include <stdlib.h>
<br>#include <stdio.h>
<br>#include <conio.h>
<br>
<br>int main(void)
<br>{
<br> /* select a driver and mode that supports */
<br> /* multiple pages. */
<br> int gdriver = EGA, gmode = EGAHI, errorcode;
<br> int x, y, ht;
<br>
<br> /* initialize graphics and local variables */
<br> initgraph(&gdriver, &gmode, "");
<br>
<br> /* read result of initialization */
<br> errorcode = graphresult();
<br> if (errorcode != grOk) /* an error occurred */
<br> {
<br> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<br> printf("Press any key to halt:");
<br> getch();
<br> exit(1); /* terminate with an error code */
<br> }
<br>
<br> x = getmaxx() / 2;
<br> y = getmaxy() / 2;
<br> ht = textheight("W");
<br>
<br> /* select the off screen page for drawing */
<br> setactivepage(1);
<br>
<br> /* draw a line on page #1 */
<br> line(0, 0, getmaxx(), getmaxy());
<br>
<br> /* output a message on page #1 */
<br> settextjustify(CENTER_TEXT, CENTER_TEXT);
<br> outtextxy(x, y, "This is page #1:");
<br> outtextxy(x, y+ht, "Press any key to halt:");
<br>
<br> /* select drawing to page #0 */
<br> setactivepage(0);
<br>
<br> /* output a message on page #0 */
<br> outtextxy(x, y, "This is page #0.");
<br> outtextxy(x, y+ht, "Press any key to view page #1:");
<br> getch();
<br>
<br> /* select page #1 as the visible page */
<br> setvisualpage(1);
<br>
<br> /* clean up */
<br> getch();
<br> closegraph();
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: setallpallette
<br>功 能: 按指定方式改变所有的调色板颜色
<br>用 法: void far setallpallette(struct palette, far *pallette);
<br>程序例:
<br>
<br>#include <graphics.h>
<br>#include <stdlib.h>
<br>#include <stdio.h>
<br>#include <conio.h>
<br>
<br>int main(void)
<br>{
<br> /* request auto detection */
<br> int gdriver = DETECT, gmode, errorcode;
<br> struct palettetype pal;
<br> int color, maxcolor, ht;
<br> int y = 10;
<br> char msg[80];
<br>
<br> /* initialize graphics and local variables */
<br> initgraph(&gdriver, &gmode, "");
<br>
<br> /* read result of initialization */
<br> errorcode = graphresult();
<br> if (errorcode != grOk) /* an error occurred */
<br> {
<br> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<br> printf("Press any key to halt:");
<br> getch();
<br> exit(1); /* terminate with an error code */
<br> }
<br>
<br> maxcolor = getmaxcolor();
<br> ht = 2 * textheight("W");
<br>
<br> /* grab a copy of the palette */
<br> getpalette(&pal);
<br>
<br> /* display the default palette colors */
<br> for (color=1; color<=maxcolor; color++)
<br> {
<br> setcolor(color);
<br> sprintf(msg, "Color: %d", color);
<br> outtextxy(1, y, msg);
<br> y += ht;
<br> }
<br>
<br> /* wait for a key */
<br> getch();
<br>
<br> /* black out the colors one by one */
<br> for (color=1; color<=maxcolor; color++)
<br> {
<br> setpalette(color, BLACK);
<br> getch();
<br> }
<br>
<br> /* restore the palette colors */
<br> setallpalette(&pal);
<br>
<br> /* clean up */
<br> getch();
<br> closegraph();
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: setaspectratio
<br>功 能: 设置图形纵横比
<br>用 法: void far setaspectratio(int xasp, int yasp);
<br>程序例:
<br>
<br>#include <graphics.h>
<br>#include <stdlib.h>
<br>#include <stdio.h>
<br>#include <conio.h>
<br>
<br>int main(void)
<br>{
<br> /* request auto detection */
<br> int gdriver = DETECT, gmode, errorcode;
<br> int xasp, yasp, midx, midy;
<br>
<br> /* initialize graphics and local variables */
<br> initgraph(&gdriver, &gmode, "");
<br>
<br> /* read result of initialization */
<br> errorcode = graphresult();
<br> if (errorcode != grOk) /* an error occurred */
<br> {
<br> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<br> printf("Press any key to halt:");
<br> getch();
<br> exit(1); /* terminate with an error code */
<br> }
<br>
<br> midx = getmaxx() / 2;
<br> midy = getmaxy() / 2;
<br> setcolor(getmaxcolor());
<br>
<br> /* get current aspect ratio settings */
<br> getaspectratio(&xasp, &yasp);
<br>
<br> /* draw normal circle */
<br> circle(midx, midy, 100);
<br> getch();
<br>
<br> /* claer the screen */
<br> cleardevice();
<br>
<br> /* adjust the aspect for a wide circle */
<br> setaspectratio(xasp/2, yasp);
<br> circle(midx, midy, 100);
<br> getch();
<br>
<br> /* adjust the aspect for a narrow circle */
<br> cleardevice();
<br> setaspectratio(xasp, yasp/2);
<br> circle(midx, midy, 100);
<br>
<br> /* clean up */
<br> getch();
<br> closegraph();
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: setbkcolor
<br>功 能: 用调色板设置当前背景颜色
<br>用 法: void far setbkcolor(int color);
<br>程序例:
<br>
<br>#include <graphics.h>
<br>#include <stdlib.h>
<br>#include <stdio.h>
<br>#include <conio.h>
<br>
<br>int main(void)
<br>{
<br> /* select a driver and mode that supports */
<br> /* multiple background colors. */
<br> int gdriver = EGA, gmode = EGAHI, errorcode;
<br> int bkcol, maxcolor, x, y;
<br> char msg[80];
<br>
<br> /* initialize graphics and local variables */
<br> initgraph(&gdriver, &gmode, "");
<br>
<br> /* read result of initialization */
<br> errorcode = graphresult();
<br> if (errorcode != grOk) /* an error occurred */
<br> {
<br> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<br> printf("Press any key to halt:");
<br> getch();
<br> exit(1); /* terminate with an error code */
<br> }
<br>
<br> /* maximum color index supported */
<br> maxcolor = getmaxcolor();
<br>
<br> /* for centering text messages */
<br> settextjustify(CENTER_TEXT, CENTER_TEXT);
<br> x = getmaxx() / 2;
<br> y = getmaxy() / 2;
<br>
<br> /* loop through the available colors */
<br> for (bkcol=0; bkcol<=maxcolor; bkcol++)
<br> {
<br> /* clear the screen */
<br> cleardevice();
<br>
<br> /* select a new background color */
<br> setbkcolor(bkcol);
<br>
<br> /* output a messsage */
<br> if (bkcol == WHITE)
<br> setcolor(EGA_BLUE);
<br> sprintf(msg, "Background color: %d", bkcol);
<br> outtextxy(x, y, msg);
<br> getch();
<br> }
<br>
<br> /* clean up */
<br> closegraph();
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: setblock
<br>功 能: 修改先前已分配的DOS存储段大小
<br>用 法: int setblock(int seg, int newsize);
<br>程序例:
<br>
<br>#include <dos.h>
<br>#include <alloc.h>
<br>#include <stdio.h>
<br>#include <stdlib.h>
<br>
<br>int main(void)
<br>{
<br> unsigned int size, segp;
<br> int stat;
<br>
<br> size = 64; /* (64 x 16) = 1024 bytes */
<br> stat = allocmem(size, &segp);
<br> if (stat == -1)
<br> printf("Allocated memory at segment: %X\n", segp);
<br> else
<br> {
<br> printf("Failed: maximum number of paragraphs available is %d\n",
<br> stat);
<br> exit(1);
<br> }
<br>
<br> stat = setblock(segp, size * 2);
<br> if (stat == -1)
<br> printf("Expanded memory block at segment: %X\n", segp);
<br> else
<br> printf("Failed: maximum number of paragraphs available is %d\n",
<br> stat);
<br>
<br> freemem(segp);
<br>
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: setbuf
<br>功 能: 把缓冲区与流相联
<br>用 法: void setbuf(FILE *steam, char *buf);
<br>程序例:
<br>
<br>#include <stdio.h>
<br>
<br>/* BUFSIZ is defined in stdio.h */
<br>char outbuf[BUFSIZ];
<br>
<br>int main(void)
<br>{
<br> /* attach a buffer to the standard output stream */
<br> setbuf(stdout, outbuf);
<br>
<br> /* put some characters into the buffer */
<br> puts("This is a test of buffered output.\n\n");
<br> puts("This output will go into outbuf\n");
<br> puts("and won't appear until the buffer\n");
<br> puts("fills up or we flush the stream.\n");
<br>
<br> /* flush the output buffer */
<br> fflush(stdout);
<br>
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: setcbrk
<br>功 能: 设置Control-break
<br>用 法: int setcbrk(int value);
<br>程序例:
<br>
<br>#include <dos.h>
<br>#include <conio.h>
<br>#include <stdio.h>
<br>
<br>int main(void)
<br>{
<br> int break_flag;
<br>
<br> printf("Enter 0 to turn control break off\n");
<br> printf("Enter 1 to turn control break on\n");
<br>
<br> break_flag = getch() - 0;
<br>
<br> setcbrk(break_flag);
<br>
<br> if (getcbrk())
<br> printf("Cntrl-brk flag is on\n");
<br> else
<br> printf("Cntrl-brk flag is off\n");
<br> return 0;
<br>}
<br>
<br>
<br>
<br>
<br>函数名: setcolor
<br>功 能: 设置当前画线颜色
<br>用 法: void far setcolor(int color);
<br>程序例:
<br>
<br>#include <graphics.h>
<br>#include <stdlib.h>
<br>#include <stdio.h>
<br>#include <conio.h>
<br>
<br>int main(void)
<br>{
<br> /* select a driver and mode that supports */
<br> /* multiple drawing colors. */
<br> int gdriver = EGA, gmode = EGAHI, errorcode;
<br> int color, maxcolor, x, y;
<br> char msg[80];
<br>
<br> /* initialize graphics and local variables */
<br> initgraph(&gdriver, &gmode, "");
<br>
<br> /* read result of initialization */
<br> errorcode = graphresult();
<br> if (errorcode != grOk) /* an error occurred */
<br> {
<br> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<br> printf("Press any key to halt:");
<br> getch();
<br> exit(1); /* terminate with an error code */
<br> }
<br>
<br> /* maximum color index supported */
<br> maxcolor = getmaxcolor();
<br>
<br> /* for centering text messages */
<br> settextjustify(CENTER_TEXT, CENTER_TEXT);
<br> x = getmaxx() / 2;
<br> y = getmaxy() / 2;
<br>
<br> /* loop through the available colors */
<br> for (color=1; color<=maxcolor; color++)
<br> {
<br> /* clear the screen */
<br> cleardevice();
<br>
<br> /* select a new background color */
<br> setcolor(color);
<br>
<br> /* output a messsage */
<br> sprintf(msg, "Color: %d", color);
<br> outtextxy(x, y, msg);
<br> getch();
<br> }
<br>
<br> /* clean up */
<br> closegraph();
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: setdate
<br>功 能: 设置DOS日期
<br>用 法: void setdate(struct date *dateblk);
<br>程序例:
<br>
<br>#include <stdio.h>
<br>#include <process.h>
<br>#include <dos.h>
<br>
<br>int main(void)
<br>{
<br> struct date reset;
<br> struct date save_date;
<br>
<br> getdate(&save_date);
<br> printf("Original date:\n");
<br> system("date");
<br>
<br> reset.da_year = 2001;
<br> reset.da_day = 1;
<br> reset.da_mon = 1;
<br> setdate(&reset);
<br>
<br> printf("Date after setting:\n");
<br> system("date");
<br>
<br> setdate(&save_date);
<br> printf("Back to original date:\n");
<br> system("date");
<br>
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: setdisk
<br>功 能: 设置当前磁盘驱动器
<br>用 法: int setdisk(int drive);
<br>程序例:
<br>
<br>#include <stdio.h>
<br>#include <dir.h>
<br>
<br>int main(void)
<br>{
<br> int save, disk, disks;
<br>
<br> /* save original drive */
<br> save = getdisk();
<br>
<br> /* print number of logic drives */
<br> disks = setdisk(save);
<br> printf("%d logical drives on the system\n\n", disks);
<br>
<br> /* print the drive letters available */
<br> printf("Available drives:\n");
<br> for (disk = 0;disk < 26;++disk)
<br> {
<br> setdisk(disk);
<br> if (disk == getdisk())
<br> printf("%c: drive is available\n", disk + 'a');
<br> }
<br> setdisk(save);
<br>
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: setdta
<br>功 能: 设置磁盘传输区地址
<br>用 法: void setdta(char far *dta);
<br>程序例:
<br>
<br>#include <process.h>
<br>#include <string.h>
<br>#include <stdio.h>
<br>#include <dos.h>
<br>
<br>int main(void)
<br>{
<br> char line[80], far *save_dta;
<br> char buffer[256] = "SETDTA test!";
<br> struct fcb blk;
<br> int result;
<br>
<br> /* get new file name from user */
<br> printf("Enter a file name to create:");
<br> gets(line);
<br>
<br> /* parse the new file name to the dta */
<br> parsfnm(line, &blk, 1);
<br> printf("%d %s\n", blk.fcb_drive, blk.fcb_name);
<br>
<br> /* request DOS services to create file */
<br> if (bdosptr(0x16, &blk, 0) == -1)
<br> {
<br> perror("Error creating file");
<br> exit(1);
<br> }
<br>
<br> /* save old dta and set new dta */
<br> save_dta = getdta();
<br> setdta(buffer);
<br>
<br> /* write new records */
<br> blk.fcb_recsize = 256;
<br> blk.fcb_random = 0L;
<br> result = randbwr(&blk, 1);
<br> printf("result = %d\n", result);
<br>
<br> if (!result)
<br> printf("Write OK\n");
<br> else
<br> {
<br> perror("Disk error");
<br> exit(1);
<br> }
<br>
<br> /* request DOS services to close the file */
<br> if (bdosptr(0x10, &blk, 0) == -1)
<br> {
<br> perror("Error closing file");
<br> exit(1);
<br> }
<br>
<br> /* reset the old dta */
<br> setdta(save_dta);
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: setfillpattern
<br>功 能: 选择用户定义的填充模式
<br>用 法: void far setfillpattern(char far *upattern, int color);
<br>程序例:
<br>
<br>#include <graphics.h>
<br>#include <stdlib.h>
<br>#include <stdio.h>
<br>#include <conio.h>
<br>
<br>int main(void)
<br>{
<br> /* request auto detection */
<br> int gdriver = DETECT, gmode, errorcode;
<br> int maxx, maxy;
<br>
<br> /* a user defined fill pattern */
<br> char pattern[8] = {0x00, 0x70, 0x20, 0x27, 0x24, 0x24, 0x07, 0x00};
<br>
<br> /* initialize graphics and local variables */
<br> initgraph(&gdriver, &gmode, "");
<br>
<br> /* read result of initialization */
<br> errorcode = graphresult();
<br> if (errorcode != grOk) /* an error occurred */
<br> {
<br> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<br> printf("Press any key to halt:");
<br> getch();
<br> exit(1); /* terminate with an error code */
<br> }
<br>
<br> maxx = getmaxx();
<br> maxy = getmaxy();
<br> setcolor(getmaxcolor());
<br>
<br> /* select a user defined fill pattern */
<br> setfillpattern(pattern, getmaxcolor());
<br>
<br> /* fill the screen with the pattern */
<br> bar(0, 0, maxx, maxy);
<br>
<br> /* clean up */
<br> getch();
<br> closegraph();
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: setfillstyle
<br>功 能: 设置填充模式和颜色
<br>用 法: void far setfillstyle(int pattern, int color);
<br>程序例:
<br>
<br>#include <graphics.h>
<br>#include <stdlib.h>
<br>#include <string.h>
<br>#include <stdio.h>
<br>#include <conio.h>
<br>
<br>/* the names of the fill styles supported */
<br>char *fname[] = { "EMPTY_FILL",
<br> "SOLID_FILL",
<br> "LINE_FILL",
<br> "LTSLASH_FILL",
<br> "SLASH_FILL",
<br> "BKSLASH_FILL",
<br> "LTBKSLASH_FILL",
<br> "HATCH_FILL",
<br> "XHATCH_FILL",
<br> "INTERLEAVE_FILL",
<br> "WIDE_DOT_FILL",
<br> "CLOSE_DOT_FILL",
<br> "USER_FILL"
<br> };
<br>
<br>int main(void)
<br>{
<br> /* request auto detection */
<br> int gdriver = DETECT, gmode, errorcode;
<br> int style, midx, midy;
<br> char stylestr[40];
<br>
<br> /* initialize graphics and local variables */
<br> initgraph(&gdriver, &gmode, "");
<br>
<br> /* read result of initialization */
<br> errorcode = graphresult();
<br> if (errorcode != grOk) /* an error occurred */
<br> {
<br> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<br> printf("Press any key to halt:");
<br> getch();
<br> exit(1); /* terminate with an error code */
<br> }
<br>
<br> midx = getmaxx() / 2;
<br> midy = getmaxy() / 2;
<br>
<br> for (style = EMPTY_FILL; style < USER_FILL; style++)
<br> {
<br> /* select the fill style */
<br> setfillstyle(style, getmaxcolor());
<br>
<br> /* convert style into a string */
<br> strcpy(stylestr, fname[style]);
<br>
<br> /* fill a bar */
<br> bar3d(0, 0, midx-10, midy, 0, 0);
<br>
<br> /* output a message */
<br> outtextxy(midx, midy, stylestr);
<br>
<br> /* wait for a key */
<br> getch();
<br> cleardevice();
<br> }
<br>
<br> /* clean up */
<br> getch();
<br> closegraph();
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: setftime
<br>功 能: 设置文件日期和时间
<br>用 法: int setftime(int handle, struct ftime *ftimep);
<br>程序例:
<br>
<br>#include <stdio.h>
<br>#include <process.h>
<br>#include <fcntl.h>
<br>#include <io.h>
<br>
<br>int main(void)
<br>{
<br> struct ftime filet;
<br> FILE *fp;
<br>
<br> if ((fp = fopen("TEST.$$$", "w")) == NULL)
<br> {
<br> perror("Error:");
<br> exit(1);
<br> }
<br>
<br> fprintf(fp, "testing...\n");
<br>
<br> /* load ftime structure with new time and date */
<br> filet.ft_tsec = 1;
<br> filet.ft_min = 1;
<br> filet.ft_hour = 1;
<br> filet.ft_day = 1;
<br> filet.ft_month = 1;
<br> filet.ft_year = 21;
<br>
<br> /* show current directory for time and date */
<br> system("dir TEST.$$$");
<br>
<br> /* change the time and date stamp*/
<br> setftime(fileno(fp), &filet);
<br>
<br> /* close and remove the temporary file */
<br> fclose(fp);
<br>
<br> system("dir TEST.$$$");
<br>
<br> unlink("TEST.$$$");
<br> return 0;
<br>}
<br>
<br>
<br>
<br>函数名: setgraphbufsize
<br>功 能: 改变内部图形缓冲区的大小
<br>用 法: unsigned far setgraphbufsize(unsigned bufsize);
<br>程序例:
<br>
<br>#include <graphics.h>
<br>#include <stdlib.h>
<br>#include <stdio.h>
<br>#include <conio.h>
<br>
<br>#define BUFSIZE 1000 /* internal graphics buffer size */
<br>
<br>int main(void)
<br>{
<br> /* request auto detection */
<br> int gdriver = DETECT, gmode, errorcode;
<br> int x, y, oldsize;
<br> char msg[80];
<br>
<br> /* set the size of the internal graphics buffer */
<br> /* before making a call to initgraph. */
<br> oldsize = setgraphbufsize(BUFSIZE);
<br>
<br> /* initialize graphics and local variables */
<br> initgraph(&gdriver, &gmode, "");
<br>
<br> /* read result of initialization */
<br> errorcode = graphresult();
<br> if (errorcode != grOk) /* an error occurred */
<br> {
<br> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<br> printf("Press any key to halt:");
<br> getch();
<br> exit(1); /* terminate with an error code */
<br> }
<br>
<br> x = getmaxx() / 2;
<br> y = getmaxy() / 2;
<br>
<br> /* output some messages */
<br> sprintf(msg, "Graphics buffer size: %d", BUFSIZE);
<br> settextjustify(CENTER_TEXT, CENTER_TEXT);
<br> outtextxy(x, y, msg);
<br> sprintf(msg, "Old graphics buffer size: %d", oldsize);
<br> outtextxy(x, y+textheight("W"), msg);
<br>
<br> /* clean up */
<br> getch();
<br> closegraph();
<br> return 0;
<br>}
<br>
<br>
<br>
<br>
<br>函数名: setgraphmode
<br>功 能: 将系统设置成图形模式且清屏
<br>用 法: void far setgraphmode(int mode);
<br>程序例:
<br>
<br>#include <graphics.h>
<br>#include <stdlib.h>
<br>#include <stdio.h>
<br>#include <conio.h>
<br>
<br>int main(void)
<br>{
<br> /* request auto detection */
<br> int gdriver = DETECT, gmode, errorcode;
<br> int x, y;
<br>
<br> /* initialize graphics and local variables */
<br> initgraph(&gdriver, &gmode, "");
<br>
<br> /* read result of initialization */
<br> errorcode = graphresult();
<br> if (errorcode != grOk) /* an error occurred */
<br> {
<br> printf("Graphics error: %s\n", grapherrormsg(errorcode));
<br> printf("Press any key to halt:");
<br> getch();
<br> exit(1); /* terminate with an error code */
<br> }
<br>
<br> x = getmaxx() / 2;
<br> y = getmaxy() / 2;
<br>
<br> /* output a message */
<br> settextjustify(CENTER_TEXT, CENTER_TEXT);
<br> outtextxy(x, y, "Press any key to exit graphics:");
<br> getch();
<br>
<br> /* restore system to text mode */
<br> restorecrtmode();
<br> printf("We're now in text mode.\n");
<br> printf("Press any key to return to graphics mode:");
<br> getch();
<br>
<br> /* return to graphics mode */
<br> setgraphmode(getgraphmode());
<br>
<br> /* output a message */
<br> settextjustify(CENTER_TEXT, CENTER_TEXT);
<br> outtextxy(x, y, "We're back in graphics mode.");
<br> outtextxy(x, y+textheight("W"), "Press any key to halt:");
<br>
<br> /* clean up */
<br> getch();
<br> closegraph();
<br> return 0;
<br>}
<br> (<a href=http://www.fanqiang.com>http://www.fanqiang.com</a>)</font> 进入【<a href=http://www.chinaunix.net>UNIX论坛</a>】</td></tr><tr><td><hr></td></tr><tr><td><b>相关文章</b> </td></tr><tr><td><a href=/a4/b2/20011027/1305001515.html>C语言库函数(W类字母)</a> <small>(2001-10-27 13:05:00)</small></font><br><a href=/a4/b2/20011027/0905001514.html>C语言库函数(V类字母)</a> <small>(2001-10-27 09:05:00)</small></font><br><a href=/a4/b2/20011027/0805011513.html>C语言库函数(U类字母)</a> <small>(2001-10-27 08:05:01)</small></font><br><a href=/a4/b2/20011027/0705001512.html>C语言库函数(T类字母)</a> <small>(2001-10-27 07:05:00)</small></font><br><a href=/a4/b2/20011026/0900001511.html>C语言库函数(S类字母) - 3</a> <small>(2001-10-26 09:00:00)</small></font><br><a href=/a4/b2/20011026/0800011510.html>C语言库函数(S类字母) - 2</a> <small>(2001-10-26 08:00:01)</small></font><br><a href=/a4/b2/20011026/0700001509.html>C语言库函数(S类字母) - 1</a> <small>(2001-10-26 07:00:00)</small></font><br><a href=/a4/b2/20011025/0900011508.html>C语言库函数(R类字母)</a> <small>(2001-10-25 09:00:01)</small></font><br><a href=/a4/b2/20011025/0800031507.html>C语言库函数(Q类字母)</a> <small>(2001-10-25 08:00:03)</small></font><br><a href=/a4/b2/20011025/0700011506.html>C语言库函数(P类字母)</a> <small>(2001-10-25 07:00:01)</small></font><br></td></tr><tr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -