📄 王大刚--c语言编程宝典--a.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0038)http://www.hjflying.8u8.com/cl/020.htm -->
<HTML><HEAD><TITLE>王大刚-->C语言编程宝典-->A</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META content="王大刚 C语言编程宝典 A" name=keywords>
<META content="王大刚 - C语言编程宝典 - A" name=description>
<STYLE>#page {
LEFT: 0px; POSITION: absolute; TOP: 0px
}
.tt3 {
FONT: 9pt/12pt "宋体"
}
.tt2 {
FONT: 12pt/15pt "宋体"
}
A {
TEXT-DECORATION: none
}
A:hover {
COLOR: blue; TEXT-DECORATION: underline
}
</STYLE>
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY text=#000000 vLink=#006699 aLink=#9900ff link=#006699 bgColor=#ffffff
leftMargin=3 topMargin=3 marginwidth="3" marginheight="3">
<TABLE cellSpacing=0 cellPadding=10 width="100%" border=0>
<TBODY>
<TR>
<TD class=tt3 vAlign=top width="8%" bgColor=#e0e0e0><STRONG><A
href="http://www.hjflying.8u8.com/cl/021.htm">后一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/019.htm">前一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/index.html">回目录</A><BR><A
href="http://www.hjflying.8u8.com/index.htm">回首页</A><BR></STRONG></TD>
<TD class=tt2 width="84%" bgColor=#f5f8f8>
<CENTER><B><FONT style="FONT-SIZE: 16.5pt" face=楷体_GB2312
color=#ff6666>A</FONT></B></CENTER>
<HR width="94%" color=#ee9b73 SIZE=1>
<P>函数名: abort <BR>功 能: 异常终止一个进程 <BR>用 法: void abort(void);
<BR>程序例: <BR>#include <stdio.h> <BR>#include <stdlib.h> <BR>
<P>int main(void) <BR>{ <BR> printf("Calling abort()\n"); <BR>
abort(); <BR> return 0; /* This is never reached */ <BR>} <BR>
<BR> <BR>
<P>函数名: abs <BR>功 能: 求整数的绝对值 <BR>用 法: int abs(int i); <BR>程序例:
<BR>#include <stdio.h> <BR>#include <math.h> <BR>
<P>int main(void) <BR>{ <BR> int number = -1234; <BR>
<P> printf("number: %d absolute value: %d\n", number,
abs(number)); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: absread, abswirte <BR>功 能: 绝对磁盘扇区读、写数据 <BR>用 法: int
absread(int drive, int nsects, int sectno, void *buffer); <BR> int
abswrite(int drive, int nsects, in tsectno, void *buffer); <BR>程序例: <BR>/*
absread example */ <BR>
<P>#include <stdio.h> <BR>#include <conio.h> <BR>#include
<process.h> <BR>#include <dos.h> <BR>
<P>int main(void) <BR>{ <BR> int i, strt, ch_out, sector; <BR>
char buf[512]; <BR>
<P> printf("Insert a diskette into drive A and press any key\n");
<BR> getch(); <BR> sector = 0; <BR> if (absread(0, 1,
sector, &buf) != 0) <BR> { <BR>
perror("Disk problem"); <BR> exit(1); <BR> }
<BR> printf("Read OK\n"); <BR> strt = 3; <BR> for (i=0;
i<80; i++) <BR> { <BR> ch_out =
buf[strt+i]; <BR> putchar(ch_out); <BR> }
<BR> printf("\n"); <BR> return(0); <BR>} <BR> <BR>
<BR> <BR>
<P>函数名: access <BR>功 能: 确定文件的访问权限 <BR>用 法: int access(const
char *filename, int amode); <BR>程序例: <BR>#include <stdio.h>
<BR>#include <io.h> <BR>
<P>int file_exists(char *filename); <BR>
<P>int main(void) <BR>{ <BR> printf("Does NOTEXIST.FIL exist: %s\n",
<BR> file_exists("NOTEXISTS.FIL") ? "YES" : "NO"); <BR> return
0; <BR>} <BR>
<P>int file_exists(char *filename) <BR>{ <BR> return
(access(filename, 0) == 0); <BR>} <BR> <BR>
<P>函数名: acos <BR>功 能: 反余弦函数 <BR>用 法: double acos(double x);
<BR>程序例: <BR>#include <stdio.h> <BR>#include <math.h> <BR>
<P>int main(void) <BR>{ <BR> double result; <BR> double x =
0.5; <BR>
<P> result = acos(x); <BR> printf("The arc cosine of %lf is
%lf\n", x, result); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: allocmem <BR>功 能: 分配DOS存储段 <BR>用 法: int
allocmem(unsigned size, unsigned *seg); <BR>程序例: <BR>#include
<dos.h> <BR>#include <alloc.h> <BR>#include <stdio.h>
<BR>
<P>int main(void) <BR>{ <BR> unsigned int size, segp; <BR> int
stat; <BR>
<P> 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> printf("Failed:
maximum number of paragraphs available is %u\n",
<BR>
stat); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: arc <BR>功 能: 画一弧线 <BR>用 法: void far arc(int x, int y,
int stangle, int endangle, int radius); <BR>程序例: <BR>#include
<graphics.h> <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> /* request auto detection
*/ <BR> int gdriver = DETECT, gmode, errorcode;
<BR> int midx, midy; <BR> int stangle = 45,
endangle = 135; <BR> int radius = 100; <BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, ""); <BR>
<P> /* read result of initialization */ <BR>
errorcode = graphresult(); /* an error occurred */
<BR> if (errorcode != grOk) <BR> {
<BR> printf("Graphics error: %s\n",
grapherrormsg(errorcode)); <BR>
printf("Press any key to halt:"); <BR>
getch(); <BR>
<P> exit(1); /* terminate
with an error code */ <BR> } <BR>
<P> midx = getmaxx() / 2; <BR> midy = getmaxy() /
2; <BR> setcolor(getmaxcolor()); <BR>
<P> /* draw arc */ <BR> arc(midx, midy, stangle,
endangle, radius); <BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: asctime <BR>功 能: 转换日期和时间为ASCII码 <BR>用 法: char
*asctime(const struct tm *tblock); <BR>程序例: <BR>#include <stdio.h>
<BR>#include <string.h> <BR>#include <time.h> <BR>
<P>int main(void) <BR>{ <BR> struct tm t; <BR>
char str[80]; <BR>
<P> /* sample loading of tm structure */ <BR>
<P> t.tm_sec = 1; /* Seconds */
<BR> t.tm_min = 30; /* Minutes */
<BR> t.tm_hour = 9; /* Hour */
<BR> t.tm_mday = 22; /* Day of the Month */
<BR> t.tm_mon = 11; /* Month */
<BR> t.tm_year = 56; /* Year - does not include
century */ <BR> t.tm_wday = 4; /* Day of the
week */ <BR> t.tm_yday = 0; /* Does
not show in asctime */ <BR> t.tm_isdst = 0;
/* Is Daylight SavTime; does not show in asctime */ <BR>
<P> /* converts structure to null terminated <BR>
string */ <BR>
<P> strcpy(str, asctime(&t)); <BR>
printf("%s\n", str); <BR>
<P> return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: asin <BR>功 能: 反正弦函数 <BR>用 法: double asin(double x);
<BR>程序例: <BR>#include <stdio.h> <BR>#include <math.h> <BR>
<P>int main(void) <BR>{ <BR> double result; <BR>
double x = 0.5; <BR>
<P> result = asin(x); <BR> printf("The arc sin of
%lf is %lf\n", x, result); <BR> return(0); <BR>} <BR>
<BR> <BR> <BR>
<P>函数名: assert <BR>功 能: 测试一个条件并可能使程序终止 <BR>用 法: void
assert(int test); <BR>程序例: <BR>#include <assert.h> <BR>#include
<stdio.h> <BR>#include <stdlib.h> <BR>
<P>struct ITEM { <BR> int key; <BR> int value;
<BR>}; <BR>
<P>/* add item to list, make sure list is not null */ <BR>void
additem(struct ITEM *itemptr) { <BR> assert(itemptr != NULL);
<BR> /* add item to list */ <BR>} <BR>
<P>int main(void) <BR>{ <BR> additem(NULL); <BR>
return 0; <BR>} <BR> <BR> <BR> <BR>
<P>函数名: atan <BR>功 能: 反正切函数 <BR>用 法: double atan(double x);
<BR>程序例: <BR>#include <stdio.h> <BR>#include <math.h> <BR>
<P>int main(void) <BR>{ <BR> double result; <BR>
double x = 0.5; <BR>
<P> result = atan(x); <BR> printf("The arc tangent
of %lf is %lf\n", x, result); <BR> return(0); <BR>} <BR>
<BR> <BR>
<P>函数名: atan2 <BR>功 能: 计算Y/X的反正切值 <BR>用 法: double atan2(double
y, double x); <BR>程序例: <BR>#include <stdio.h> <BR>#include
<math.h> <BR>
<P>int main(void) <BR>{ <BR> double result; <BR>
double x = 90.0, y = 45.0; <BR>
<P> result = atan2(y, x); <BR> printf("The arc
tangent ratio of %lf is %lf\n", (y / x), result); <BR> return
0; <BR>} <BR> <BR> <BR>
<P>函数名: atexit <BR>功 能: 注册终止函数 <BR>用 法: int atexit(atexit_t
func); <BR>程序例: <BR>#include <stdio.h> <BR>#include <stdlib.h>
<BR>
<P>void exit_fn1(void) <BR>{ <BR> printf("Exit function #1
called\n"); <BR>} <BR>
<P>void exit_fn2(void) <BR>{ <BR> printf("Exit function #2
called\n"); <BR>} <BR>
<P>int main(void) <BR>{ <BR> /* post exit function #1 */
<BR> atexit(exit_fn1); <BR> /* post exit function
#2 */ <BR> atexit(exit_fn2); <BR> return 0; <BR>}
<BR> <BR> <BR> <BR>
<P>函数名: atof <BR>功 能: 把字符串转换成浮点数 <BR>用 法: double atof(const
char *nptr); <BR>程序例: <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>
<P>int main(void) <BR>{ <BR> float f; <BR> char
*str = "12345.67"; <BR>
<P> f = atof(str); <BR> printf("string = %s float
= %f\n", str, f); <BR> return 0; <BR>} <BR> <BR>
<BR>
<P>函数名: atoi <BR>功 能: 把字符串转换成长整型数 <BR>用 法: int atoi(const char
*nptr); <BR>程序例: <BR>#include <stdlib.h> <BR>#include
<stdio.h> <BR>
<P>int main(void) <BR>{ <BR> int n; <BR> char *str
= "12345.67"; <BR>
<P> n = atoi(str); <BR> printf("string = %s
integer = %d\n", str, n); <BR> return 0; <BR>} <BR>
<BR> <BR>
<P>函数名: atol <BR>功 能: 把字符串转换成长整型数 <BR>用 法: long atol(const
char *nptr); <BR>程序例: <BR>
<P>#include <stdlib.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> long l; <BR> char
*str = "98765432"; <BR>
<P> l = atol(lstr); <BR> printf("string = %s
integer = %ld\n", str, l); <BR> return(0); <BR>} <BR>
<BR>
<HR width="94%" color=#ee9b73 SIZE=1>
</TD>
<TD class=tt3 vAlign=bottom width="8%" bgColor=#e0e0e0><STRONG><A
href="http://www.hjflying.8u8.com/cl/021.htm">后一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/019.htm">前一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/index.html">回目录</A><BR><A
href="http://www.hjflying.8u8.com/index.htm">回首页</A><BR></STRONG></TD></TR></TBODY></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -