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

📄 fc.htm

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

⌨️ 快捷键说明

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