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

📄 fc.htm

📁 C语言编程宝典.rar,学习C语言的经典初级教程
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write(handle, buf, strlen(buf));

<P>&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;

<P>函数名: clock
<BR>功&nbsp; 能: 确定处理器时间
<BR>用&nbsp; 法: clock_t clock(void);
<BR>程序例:

<P>#include &lt;time.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;dos.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; clock_t start, end;
<BR>&nbsp;&nbsp; start = clock();

<P>&nbsp;&nbsp; delay(2000);

<P>&nbsp;&nbsp; end = clock();
<BR>&nbsp;&nbsp; printf("The time was: %f\n", (end - start) / CLK_TCK);

<P>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: closegraph
<BR>功&nbsp; 能: 关闭图形系统
<BR>用&nbsp; 法: void far closegraph(void);
<BR>程序例:

<P>#include &lt;graphics.h>
<BR>#include &lt;stdlib.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;conio.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; /* request auto detection */
<BR>&nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode;
<BR>&nbsp;&nbsp; int x, y;

<P>&nbsp;&nbsp; /* initialize graphics mode */
<BR>&nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode, "");

<P>&nbsp;&nbsp; /* read result of initialization */
<BR>&nbsp;&nbsp; errorcode = graphresult();

<P>&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; }

<P>&nbsp;&nbsp; x = getmaxx() / 2;
<BR>&nbsp;&nbsp; y = getmaxy() / 2;

<P>&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:");

<P>&nbsp;&nbsp; /* wait for a key */
<BR>&nbsp;&nbsp; getch();

<P>&nbsp;&nbsp; /* closes down the graphics system */
<BR>&nbsp;&nbsp; closegraph();

<P>&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;

<P>函数名: clreol
<BR>功&nbsp; 能: 在文本窗口中清除字符到行末
<BR>用&nbsp; 法: void clreol(void);
<BR>程序例:

<P>#include &lt;conio.h>

<P>int main(void)

<P>{
<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();

<P>&nbsp;&nbsp; clreol();
<BR>&nbsp;&nbsp; getch();

<P>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: clrscr
<BR>功&nbsp; 能: 清除文本模式窗口
<BR>用&nbsp; 法: void clrscr(void);
<BR>程序例:

<P>#include &lt;conio.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; int i;

<P>&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();

<P>&nbsp;&nbsp; clrscr();
<BR>&nbsp;&nbsp; cprintf("The screen has been cleared!");
<BR>&nbsp;&nbsp; getch();

<P>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: coreleft
<BR>功&nbsp; 能: 返回未使用内存的大小
<BR>用&nbsp; 法: unsigned coreleft(void);
<BR>程序例:

<P>#include &lt;stdio.h>
<BR>#include &lt;alloc.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; printf("The difference between the highest allocated block
and\n");
<BR>&nbsp;&nbsp; printf("the top of the heap is: %lu bytes\n", (unsigned
long) coreleft());

<P>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;

<P>函数名: cos
<BR>功&nbsp; 能: 余弦函数
<BR>用&nbsp; 法: double cos(double x);
<BR>程序例:

<P>#include &lt;stdio.h>
<BR>#include &lt;math.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; double result;
<BR>&nbsp;&nbsp; double x = 0.5;

<P>&nbsp;&nbsp; result = cos(x);
<BR>&nbsp;&nbsp; printf("The cosine of %lf is %lf\n", x, result);
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: cosh
<BR>功&nbsp; 能: 双曲余弦函数
<BR>用&nbsp; 法: dluble cosh(double x);
<BR>程序例:

<P>#include &lt;stdio.h>
<BR>#include &lt;math.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; double result;
<BR>&nbsp;&nbsp; double x = 0.5;

<P>&nbsp;&nbsp; result = cosh(x);
<BR>&nbsp;&nbsp; printf("The hyperboic cosine of %lf is %lf\n", x, result);
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: country
<BR>功&nbsp; 能: 返回与国家有关的信息
<BR>用&nbsp; 法: struct COUNTRY *country(int countrycode, struct country
*country);
<BR>程序例:

<P>#include &lt;dos.h>
<BR>#include &lt;stdio.h>

<P>#define USA 0

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; struct COUNTRY country_info;

<P>&nbsp;&nbsp; country(USA, &amp;country_info);
<BR>&nbsp;&nbsp; printf("The currency symbol for the USA is: %s\n",
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; country_info.co_curr);
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: cprintf
<BR>功&nbsp; 能: 送格式化输出至屏幕
<BR>用&nbsp; 法: int cprintf(const char *format[, argument, ...]);
<BR>程序例:

<P>#include &lt;conio.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; /* clear the screen */
<BR>&nbsp;&nbsp; clrscr();

<P>&nbsp;&nbsp; /* create a text window */
<BR>&nbsp;&nbsp; window(10, 10, 80, 25);

<P>&nbsp;&nbsp; /* output some text in the window */
<BR>&nbsp;&nbsp; cprintf("Hello world\r\n");

<P>&nbsp;&nbsp; /* wait for a key */
<BR>&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: cputs
<BR>功&nbsp; 能: 写字符到屏幕
<BR>用&nbsp; 法: void cputs(const char *string);
<BR>程序例:

<P>#include &lt;conio.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; /* clear the screen */
<BR>&nbsp;&nbsp; clrscr();

<P>&nbsp;&nbsp; /* create a text window */
<BR>&nbsp;&nbsp; window(10, 10, 80, 25);

<P>&nbsp;&nbsp; /* output some text in the window */
<BR>&nbsp;&nbsp; cputs("This is within the window\r\n");

<P>&nbsp;&nbsp; /* wait for a key */
<BR>&nbsp;&nbsp; getch();
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: _creat&nbsp; creat
<BR>功&nbsp; 能: 创建一个新文件或重写一个已存在的文件
<BR>用&nbsp; 法: int creat (const char *filename, int permiss);
<BR>程序例:

<P>#include &lt;sys\stat.h>
<BR>#include &lt;string.h>
<BR>#include &lt;fcntl.h>
<BR>#include &lt;io.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; int handle;
<BR>&nbsp;&nbsp; char buf[11] = "0123456789";

<P>&nbsp;&nbsp; /* change the default file mode from text to binary */
<BR>&nbsp;&nbsp; _fmode = O_BINARY;

<P>&nbsp;&nbsp; /* create a binary file for reading and writing */
<BR>&nbsp;&nbsp; handle = creat("DUMMY.FIL", S_IREAD | S_IWRITE);

<P>&nbsp;&nbsp; /* write 10 bytes to the file */
<BR>&nbsp;&nbsp; write(handle, buf, strlen(buf));

<P>&nbsp;&nbsp; /* close the file */
<BR>&nbsp;&nbsp; close(handle);
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;

<P>函数名: creatnew
<BR>功&nbsp; 能: 创建一个新文件
<BR>用&nbsp; 法: int creatnew(const char *filename, int attrib);
<BR>程序例:

<P>#include &lt;string.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;errno.h>
<BR>#include &lt;dos.h>
<BR>#include &lt;io.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; int handle;
<BR>&nbsp;&nbsp; char buf[11] = "0123456789";

<P>&nbsp;&nbsp; /* attempt to create a file that doesn't already exist
*/
<BR>&nbsp;&nbsp; handle = creatnew("DUMMY.FIL", 0);

<P>&nbsp;&nbsp; if (handle == -1)
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("DUMMY.FIL already exists.\n");
<BR>&nbsp;&nbsp; else
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("DUMMY.FIL successfully created.\n");
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; write(handle, buf, strlen(buf));
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; close(handle);
<BR>&nbsp;&nbsp; }
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: creattemp
<BR>功&nbsp; 能: 创建一个新文件或重写一个已存在的文件
<BR>用&nbsp; 法: int creattemp(const char *filename, int attrib);
<BR>程序例:

<P>#include &lt;string.h>
<BR>#include &lt;stdio.h>
<BR>#include &lt;io.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; int handle;
<BR>&nbsp;&nbsp; char pathname[128];

<P>&nbsp;&nbsp; strcpy(pathname, "\\");

<P>&nbsp;&nbsp; /* create a unique file in the root directory */
<BR>&nbsp;&nbsp; handle = creattemp(pathname, 0);

<P>&nbsp;&nbsp; printf("%s was the unique file created.\n", pathname);
<BR>&nbsp;&nbsp; close(handle);
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: cscanf
<BR>功&nbsp; 能: 从控制台执行格式化输入
<BR>用&nbsp; 法: int cscanf(char *format[,argument, ...]);
<BR>程序例:

<P>#include &lt;conio.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; char string[80];

<P>&nbsp;&nbsp; /* clear the screen */
<BR>&nbsp;&nbsp; clrscr();

<P>&nbsp;&nbsp; /* Prompt the user for input */
<BR>&nbsp;&nbsp; cprintf("Enter a string with no spaces:");

<P>&nbsp;&nbsp; /* read the input */
<BR>&nbsp;&nbsp; cscanf("%s", string);

<P>&nbsp;&nbsp; /* display what was read */
<BR>&nbsp;&nbsp; cprintf("\r\nThe string entered is: %s", string);
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: ctime
<BR>功&nbsp; 能: 把日期和时间转换为字符串
<BR>用&nbsp; 法: char *ctime(const time_t *time);
<BR>程序例:

<P>#include &lt;stdio.h>
<BR>#include &lt;time.h>

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; time_t t;

<P>&nbsp;&nbsp; time(&amp;t);
<BR>&nbsp;&nbsp; printf("Today's date and time: %s\n", ctime(&amp;t));
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;
<BR>&nbsp;
<BR>&nbsp;

<P>函数名: ctrlbrk
<BR>功&nbsp; 能: 设置Ctrl-Break处理程序
<BR>用&nbsp; 法: void ctrlbrk(*fptr)(void);
<BR>程序例:

<P>#include &lt;stdio.h>
<BR>#include &lt;dos.h>

<P>#define ABORT 0

<P>int c_break(void)
<BR>{
<BR>&nbsp;&nbsp; printf("Control-Break pressed.&nbsp; Program aborting
...\n");
<BR>&nbsp;&nbsp; return (ABORT);
<BR>}

<P>int main(void)
<BR>{
<BR>&nbsp;&nbsp; ctrlbrk(c_break);
<BR>&nbsp;&nbsp; for(;;)
<BR>&nbsp;&nbsp; {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("Looping... Press &lt;Ctrl-Break>
to quit:\n");
<BR>&nbsp;&nbsp; }
<BR>&nbsp;&nbsp; return 0;
<BR>}
<BR>&nbsp;

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<A HREF="index.html">返回目录</A>

<P>
</BODY>
</HTML>

⌨️ 快捷键说明

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