📄 fc.htm
字号:
{ <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>
} </font>
<P><font color="#003399"> midx = getmaxx() / 2; <BR>
midy = getmaxy() / 2; <BR>
setcolor(getmaxcolor()); </font>
<P><font color="#003399"> /* for centering screen messages */ <BR>
settextjustify(CENTER_TEXT, CENTER_TEXT); </font>
<P><font color="#003399"> /* output a message to the screen */ <BR>
outtextxy(midx, midy, "press any key to clear the screen:"); </font>
<P><font color="#003399"> /* wait for a key */ <BR>
getch(); </font>
<P><font color="#003399"> /* clear the screen */ <BR>
cleardevice(); </font>
<P><font color="#003399"> /* output another message */ <BR>
outtextxy(midx, midy, "press any key to quit:"); </font>
<P><font color="#003399"> /* clean up */ <BR>
getch(); <BR>
closegraph(); <BR>
return 0; <BR>
} <BR>
<BR>
<BR>
</font>
<P><font color="#003399">函数名: clearerr <BR>
功 能: 复位错误标志 <BR>
用 法:void clearerr(FILE *stream); <BR>
程序例: </font>
<P><font color="#003399">#include <stdio.h> </font>
<P><font color="#003399">int main(void) <BR>
{ <BR>
FILE *fp; <BR>
char ch; </font>
<P><font color="#003399"> /* open a file for writing */ <BR>
fp = fopen("DUMMY.FIL", "w"); </font>
<P><font color="#003399"> /* force an error condition by attempting
to read */ <BR>
ch = fgetc(fp); <BR>
printf("%c\n",ch); </font>
<P><font color="#003399"> if (ferror(fp)) <BR>
{ <BR>
/* display an error message */ <BR>
printf("Error reading from DUMMY.FIL\n"); </font>
<P><font color="#003399"> /* reset the error and
EOF indicators */ <BR>
clearerr(fp); <BR>
} </font>
<P><font color="#003399"> fclose(fp); <BR>
return 0; <BR>
} <BR>
<BR>
<BR>
</font>
<P><font color="#003399">函数名: clearviewport <BR>
功 能: 清除图形视区 <BR>
用 法: void far clearviewport(void); <BR>
程序例: </font>
<P><font color="#003399">#include <graphics.h> <BR>
#include <stdlib.h> <BR>
#include <stdio.h> <BR>
#include <conio.h> </font>
<P><font color="#003399">#define CLIP_ON 1 /* activates clipping in
viewport */ </font>
<P><font color="#003399">int main(void) <BR>
{ <BR>
/* request auto detection */ <BR>
int gdriver = DETECT, gmode, errorcode; <BR>
int ht; </font>
<P><font color="#003399"> /* initialize graphics and local variables
*/ <BR>
initgraph(&gdriver, &gmode, ""); </font>
<P><font color="#003399"> /* 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>
} </font>
<P><font color="#003399"> setcolor(getmaxcolor()); <BR>
ht = textheight("W"); </font>
<P><font color="#003399"> /* message in default full-screen viewport
*/ <BR>
outtextxy(0, 0, "* <-- (0, 0) in default viewport"); </font>
<P><font color="#003399"> /* create a smaller viewport */ <BR>
setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON); </font>
<P><font color="#003399"> /* display some messages */ <BR>
outtextxy(0, 0, "* <-- (0, 0) in smaller viewport"); <BR>
outtextxy(0, 2*ht, "Press any key to clear viewport:"); </font>
<P><font color="#003399"> /* wait for a key */ <BR>
getch(); </font>
<P><font color="#003399"> /* clear the viewport */ <BR>
clearviewport(); </font>
<P><font color="#003399"> /* output another message */ <BR>
outtextxy(0, 0, "Press any key to quit:"); </font>
<P><font color="#003399"> /* clean up */ <BR>
getch(); <BR>
closegraph(); <BR>
return 0; <BR>
} <BR>
<BR>
<BR>
</font>
<P><font color="#003399">函数名: _close, close <BR>
功 能: 关闭文件句柄 <BR>
用 法: int close(int handle); <BR>
程序例: </font>
<P><font color="#003399">#include <string.h> <BR>
#include <stdio.h> <BR>
#include <fcntl.h> <BR>
#include <io.h> </font>
<P><font color="#003399">main() <BR>
{ <BR>
int handle; <BR>
char buf[11] = "0123456789"; </font>
<P><font color="#003399"> /* create a file containing 10 bytes */
<BR>
handle = open("NEW.FIL", O_CREAT); <BR>
if (handle > -1) <BR>
{ <BR>
write(handle, buf, strlen(buf)); </font>
<P><font color="#003399"> /* close the file
*/ <BR>
close(handle); <BR>
} <BR>
else <BR>
{ <BR>
printf("Error opening file\n"); <BR>
} <BR>
return 0; <BR>
} <BR>
<BR>
<BR>
</font>
<P><font color="#003399">函数名: clock <BR>
功 能: 确定处理器时间 <BR>
用 法: clock_t clock(void); <BR>
程序例: </font>
<P><font color="#003399">#include <time.h> <BR>
#include <stdio.h> <BR>
#include <dos.h> </font>
<P><font color="#003399">int main(void) <BR>
{ <BR>
clock_t start, end; <BR>
start = clock(); </font>
<P><font color="#003399"> delay(2000); </font>
<P><font color="#003399"> end = clock(); <BR>
printf("The time was: %f\n", (end - start) / CLK_TCK); </font>
<P><font color="#003399"> return 0; <BR>
} <BR>
<BR>
<BR>
</font>
<P><font color="#003399">函数名: closegraph <BR>
功 能: 关闭图形系统 <BR>
用 法: void far closegraph(void); <BR>
程序例: </font>
<P><font color="#003399">#include <graphics.h> <BR>
#include <stdlib.h> <BR>
#include <stdio.h> <BR>
#include <conio.h> </font>
<P><font color="#003399">int main(void) <BR>
{ <BR>
/* request auto detection */ <BR>
int gdriver = DETECT, gmode, errorcode; <BR>
int x, y; </font>
<P><font color="#003399"> /* initialize graphics mode */ <BR>
initgraph(&gdriver, &gmode, ""); </font>
<P><font color="#003399"> /* read result of initialization */ <BR>
errorcode = graphresult(); </font>
<P><font color="#003399"> if (errorcode != grOk) /* an error
<BR>
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>
} </font>
<P><font color="#003399"> x = getmaxx() / 2; <BR>
y = getmaxy() / 2; </font>
<P><font color="#003399"> /* output a message */ <BR>
settextjustify(CENTER_TEXT, CENTER_TEXT); <BR>
outtextxy(x, y, "Press a key to close the graphics system:"); </font>
<P><font color="#003399"> /* wait for a key */ <BR>
getch(); </font>
<P><font color="#003399"> /* closes down the graphics system */ <BR>
closegraph(); </font>
<P><font color="#003399"> printf("We're now back in text mode.\n");
<BR>
printf("Press any key to halt:"); <BR>
getch(); <BR>
return 0; <BR>
} <BR>
<BR>
<BR>
</font>
<P><font color="#003399">函数名: clreol <BR>
功 能: 在文本窗口中清除字符到行末 <BR>
用 法: void clreol(void); <BR>
程序例: </font>
<P><font color="#003399">#include <conio.h> </font>
<P><font color="#003399">int main(void) </font>
<P><font color="#003399">{ <BR>
clrscr(); <BR>
cprintf("The function CLREOL clears all characters from the\r\n");
<BR>
cprintf("cursor position to the end of the line within the\r\n");
<BR>
cprintf("current text window, without moving the cursor.\r\n");
<BR>
cprintf("Press any key to continue . . ."); <BR>
gotoxy(14, 4); <BR>
getch(); </font>
<P><font color="#003399"> clreol(); <BR>
getch(); </font>
<P><font color="#003399"> return 0; <BR>
} <BR>
<BR>
<BR>
</font>
<P><font color="#003399">函数名: clrscr <BR>
功 能: 清除文本模式窗口 <BR>
用 法: void clrscr(void); <BR>
程序例: </font>
<P><font color="#003399">#include <conio.h> </font>
<P><font color="#003399">int main(void) <BR>
{ <BR>
int i; </font>
<P><font color="#003399"> clrscr(); <BR>
for (i = 0; i < 20; i++) <BR>
cprintf("%d\r\n", i); <BR>
cprintf("\r\nPress any key to clear screen"); <BR>
getch(); </font>
<P><font color="#003399"> clrscr(); <BR>
cprintf("The screen has been cleared!"); <BR>
getch(); </font>
<P><font color="#003399"> return 0; <BR>
} <BR>
<BR>
<BR>
</font>
<P><font color="#003399">函数名: coreleft <BR>
功 能: 返回未使用内存的大小 <BR>
用 法: unsigned coreleft(void); <BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -