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

📄 fc.htm

📁 c语言基本的应用便于初学者学习使用 简单易懂
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=gb_2312-80">
<meta name="Author" content="wdg">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>网上学堂 --> C语言编程宝典之一 -->函数名: c</title>
</head>

<body>
<div align="center"><center>

<table border="1" cellpadding="4" width="640"
bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF">
    <tr>
        <td bgcolor="#FFE6B0" bordercolor="#8080FF" class="p9"><font
        color="#BB0000">导航条:--&gt;</font> <a
        href="../../index.html">网上学堂</a> --&gt; <a
        href="../tcindex.htm"><font face="宋体">C</font>语言编程宝典之一</a>
        --&gt;函数名: c</td>
    </tr>
    <tr>
        <td bordercolor="#8080FF" class="p9">函数名: cabs <br>
        功&nbsp; 能: 计算复数的绝对值 <br>
        用&nbsp; 法: double cabs(struct complex z); <br>
        程序例: <p>#include &lt;stdio.h&gt; <br>
        #include &lt;math.h&gt; </p>
        <p>int main(void) <br>
        { <br>
        &nbsp;&nbsp; struct complex z; <br>
        &nbsp;&nbsp; double val; </p>
        <p>&nbsp;&nbsp; z.x = 2.0; <br>
        &nbsp;&nbsp; z.y = 1.0; <br>
        &nbsp;&nbsp; val = cabs(z); </p>
        <p>&nbsp;&nbsp; printf(&quot;The absolute value of %.2lfi
        %.2lfj is %.2lf&quot;, z.x, z.y, val); <br>
        &nbsp;&nbsp; return 0; <br>
        } <br>
        &nbsp; <br>
        &nbsp; <br>
        &nbsp; </p>
        <p>函数名: calloc <br>
        功&nbsp; 能: 分配主存储器 <br>
        用&nbsp; 法: void *calloc(size_t nelem, size_t elsize);
        <br>
        程序例: </p>
        <p>#include &lt;stdio.h&gt; <br>
        #include &lt;alloc.h&gt; </p>
        <p>int main(void) <br>
        { <br>
        &nbsp;&nbsp; char *str = NULL; </p>
        <p>&nbsp;&nbsp; /* allocate memory for string */ <br>
        &nbsp;&nbsp; str = calloc(10, sizeof(char)); </p>
        <p>&nbsp;&nbsp; /* copy &quot;Hello&quot; into string */ <br>
        &nbsp;&nbsp; strcpy(str, &quot;Hello&quot;); </p>
        <p>&nbsp;&nbsp; /* display string */ <br>
        &nbsp;&nbsp; printf(&quot;String is %s\n&quot;, str); </p>
        <p>&nbsp;&nbsp; /* free memory */ <br>
        &nbsp;&nbsp; free(str); </p>
        <p>&nbsp;&nbsp; return 0; <br>
        } <br>
        &nbsp; <br>
        &nbsp; <br>
        &nbsp; </p>
        <p>函数名: ceil <br>
        功&nbsp; 能: 向上舍入 <br>
        用&nbsp; 法: double ceil(double x); <br>
        程序例: </p>
        <p>#include &lt;math.h&gt; <br>
        #include &lt;stdio.h&gt; </p>
        <p>int main(void) <br>
        { <br>
        &nbsp;&nbsp; double number = 123.54; <br>
        &nbsp;&nbsp; double down, up; </p>
        <p>&nbsp;&nbsp; down = floor(number); <br>
        &nbsp;&nbsp; up = ceil(number); </p>
        <p>&nbsp;&nbsp; printf(&quot;original number&nbsp;&nbsp;&nbsp;&nbsp;
        %5.2lf\n&quot;, number); <br>
        &nbsp;&nbsp; printf(&quot;number rounded down
        %5.2lf\n&quot;, down); <br>
        &nbsp;&nbsp; printf(&quot;number rounded up&nbsp;&nbsp;
        %5.2lf\n&quot;, up); </p>
        <p>&nbsp;&nbsp; return 0; <br>
        } <br>
        &nbsp; <br>
        &nbsp; <br>
        &nbsp; </p>
        <p>函数名: cgets <br>
        功&nbsp; 能: 从控制台读字符串 <br>
        用&nbsp; 法: char *cgets(char *str); <br>
        程序例: </p>
        <p>#include &lt;stdio.h&gt; <br>
        #include &lt;conio.h&gt; </p>
        <p>int main(void) <br>
        { <br>
        &nbsp;&nbsp; char buffer[83]; <br>
        &nbsp;&nbsp; char *p; </p>
        <p>&nbsp;&nbsp; /* There's space for 80 characters plus
        the NULL terminator */ <br>
        &nbsp;&nbsp; buffer[0] = 81; </p>
        <p>&nbsp;&nbsp; printf(&quot;Input some chars:&quot;); <br>
        &nbsp;&nbsp; p = cgets(buffer); <br>
        &nbsp;&nbsp; printf(&quot;\ncgets read %d characters:
        \&quot;%s\&quot;\n&quot;, buffer[1], p); <br>
        &nbsp;&nbsp; printf(&quot;The returned pointer is %p,
        buffer[0] is at %p\n&quot;, p, &amp;buffer); </p>
        <p>&nbsp;&nbsp; /* Leave room for 5 characters plus the
        NULL terminator */ <br>
        &nbsp;&nbsp; buffer[0] = 6; </p>
        <p>&nbsp;&nbsp; printf(&quot;Input some chars:&quot;); <br>
        &nbsp;&nbsp; p = cgets(buffer); <br>
        &nbsp;&nbsp; printf(&quot;\ncgets read %d characters:
        \&quot;%s\&quot;\n&quot;, buffer[1], p); <br>
        &nbsp;&nbsp; printf(&quot;The returned pointer is %p,
        buffer[0] is at %p\n&quot;, p, &amp;buffer); <br>
        &nbsp;&nbsp; return 0; <br>
        } <br>
        &nbsp; <br>
        &nbsp; <br>
        &nbsp; </p>
        <p>函数名: chdir <br>
        功&nbsp; 能: 改变工作目录 <br>
        用&nbsp; 法: int chdir(const char *path); <br>
        程序例: </p>
        <p>#include &lt;stdio.h&gt; <br>
        #include &lt;stdlib.h&gt; <br>
        #include &lt;dir.h&gt; </p>
        <p>char old_dir[MAXDIR]; <br>
        char new_dir[MAXDIR]; </p>
        <p>int main(void) <br>
        { <br>
        &nbsp;&nbsp; if (getcurdir(0, old_dir)) <br>
        &nbsp;&nbsp; { <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        perror(&quot;getcurdir()&quot;); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <br>
        &nbsp;&nbsp; } <br>
        &nbsp;&nbsp; printf(&quot;Current directory is:
        \\%s\n&quot;, old_dir); </p>
        <p>&nbsp;&nbsp; if (chdir(&quot;\\&quot;)) <br>
        &nbsp;&nbsp; { <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        perror(&quot;chdir()&quot;); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <br>
        &nbsp;&nbsp; } </p>
        <p>&nbsp;&nbsp; if (getcurdir(0, new_dir)) <br>
        &nbsp;&nbsp; { <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        perror(&quot;getcurdir()&quot;); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <br>
        &nbsp;&nbsp; } <br>
        &nbsp;&nbsp; printf(&quot;Current directory is now:
        \\%s\n&quot;, new_dir); </p>
        <p>&nbsp;&nbsp; printf(&quot;\nChanging back to orignal
        directory: \\%s\n&quot;, old_dir); <br>
        &nbsp;&nbsp; if (chdir(old_dir)) <br>
        &nbsp;&nbsp; { <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        perror(&quot;chdir()&quot;); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); <br>
        &nbsp;&nbsp; } </p>
        <p>&nbsp;&nbsp; return 0; <br>
        } <br>
        &nbsp; <br>
        &nbsp; </p>
        <p>函数名: _chmod, chmod <br>
        功&nbsp; 能: 改变文件的访问方式 <br>
        用&nbsp; 法: int chmod(const char *filename, int
        permiss); <br>
        程序例: </p>
        <p>#include &lt;sys\stat.h&gt; <br>
        #include &lt;stdio.h&gt; <br>
        #include &lt;io.h&gt; </p>
        <p>void make_read_only(char *filename); </p>
        <p>int main(void) <br>
        { <br>
        &nbsp;&nbsp; make_read_only(&quot;NOTEXIST.FIL&quot;); <br>
        &nbsp;&nbsp; make_read_only(&quot;MYFILE.FIL&quot;); <br>
        &nbsp;&nbsp; return 0; <br>
        } </p>
        <p>void make_read_only(char *filename) <br>
        { <br>
        &nbsp;&nbsp; int stat; </p>
        <p>&nbsp;&nbsp; stat = chmod(filename, S_IREAD); <br>
        &nbsp;&nbsp; if (stat) <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;Couldn't make
        %s read-only\n&quot;, filename); <br>
        &nbsp;&nbsp; else <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;Made %s
        read-only\n&quot;, filename); <br>
        } <br>
        &nbsp; <br>
        &nbsp; <br>
        &nbsp; </p>
        <p>函数名: chsize <br>
        功&nbsp; 能: 改变文件大小 <br>
        用&nbsp; 法: int chsize(int handle, long size); <br>
        程序例: </p>
        <p>#include &lt;string.h&gt; <br>
        #include &lt;fcntl.h&gt; <br>
        #include &lt;io.h&gt; </p>
        <p>int main(void) <br>
        { <br>
        &nbsp;&nbsp; int handle; <br>
        &nbsp;&nbsp; char buf[11] = &quot;0123456789&quot;; </p>
        <p>&nbsp;&nbsp; /* create text file containing 10 bytes
        */ <br>
        &nbsp;&nbsp; handle = open(&quot;DUMMY.FIL&quot;,
        O_CREAT); <br>
        &nbsp;&nbsp; write(handle, buf, strlen(buf)); </p>
        <p>&nbsp;&nbsp; /* truncate the file to 5 bytes in size
        */ <br>
        &nbsp;&nbsp; chsize(handle, 5); </p>
        <p>&nbsp;&nbsp; /* close the file */ <br>
        &nbsp;&nbsp; close(handle); <br>
        &nbsp;&nbsp; return 0; <br>
        } <br>
        &nbsp; <br>
        &nbsp; </p>
        <p>函数名: circle <br>
        功&nbsp; 能: 在给定半径以(x, y)为圆心画圆 <br>
        用&nbsp; 法: void far circle(int x, int y, int radius);
        <br>
        程序例: </p>
        <p>#include &lt;graphics.h&gt; <br>
        #include &lt;stdlib.h&gt; <br>
        #include &lt;stdio.h&gt; <br>
        #include &lt;conio.h&gt; </p>
        <p>int main(void) <br>
        { <br>
        &nbsp;&nbsp; /* request auto detection */ <br>
        &nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; <br>
        &nbsp;&nbsp; int midx, midy; <br>
        &nbsp;&nbsp; int radius = 100; </p>
        <p>&nbsp;&nbsp; /* initialize graphics and local
        variables */ <br>
        &nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode,
        &quot;&quot;); </p>
        <p>&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(&quot;Graphics
        error: %s\n&quot;, grapherrormsg(errorcode)); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;Press any key
        to halt:&quot;); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; getch(); <br>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(1); /* terminate with
        an error code */ <br>
        &nbsp;&nbsp; } </p>
        <p>&nbsp;&nbsp; midx = getmaxx() / 2; <br>
        &nbsp;&nbsp; midy = getmaxy() / 2; <br>
        &nbsp;&nbsp; setcolor(getmaxcolor()); </p>
        <p>&nbsp;&nbsp; /* draw the circle */ <br>
        &nbsp;&nbsp; circle(midx, midy, radius); </p>
        <p>&nbsp;&nbsp; /* clean up */ <br>
        &nbsp;&nbsp; getch(); <br>
        &nbsp;&nbsp; closegraph(); <br>
        &nbsp;&nbsp; return 0; <br>
        } <br>
        &nbsp; <br>
        &nbsp; <br>
        &nbsp; </p>
        <p>函数名: cleardevice <br>
        功&nbsp; 能: 清除图形屏幕 <br>
        用&nbsp; 法: void far cleardevice(void); <br>
        程序例: </p>
        <p>#include &lt;graphics.h&gt; <br>
        #include &lt;stdlib.h&gt; <br>
        #include &lt;stdio.h&gt; <br>
        #include &lt;conio.h&gt; </p>
        <p>int main(void) <br>
        { <br>
        &nbsp;&nbsp; /* request auto detection */ <br>
        &nbsp;&nbsp; int gdriver = DETECT, gmode, errorcode; <br>
        &nbsp;&nbsp; int midx, midy; </p>
        <p>&nbsp;&nbsp; /* initialize graphics and local
        variables */ <br>
        &nbsp;&nbsp; initgraph(&amp;gdriver, &amp;gmode,
        &quot;&quot;); </p>

⌨️ 快捷键说明

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