📄 王大刚--c语言编程宝典--p.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0038)http://www.hjflying.8u8.com/cl/033.htm -->
<HTML><HEAD><TITLE>王大刚-->C语言编程宝典-->P</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META content="王大刚 C语言编程宝典 P" name=keywords>
<META content="王大刚 - C语言编程宝典 - P" 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/034.htm">后一页</A><BR><A
href="http://www.hjflying.8u8.com/cl/032.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>P</FONT></B></CENTER>
<HR width="94%" color=#ee9b73 SIZE=1>
<P>函数名: parsfnm <BR>功 能: 分析文件名 <BR>用 法: char *parsfnm (char
*cmdline, struct fcb *fcbptr, int option); <BR>程序例: <BR>
<P>#include <process.h> <BR>#include <string.h> <BR>#include
<stdio.h> <BR>#include <dos.h> <BR>
<P>int main(void) <BR>{ <BR> char line[80]; <BR>
struct fcb blk; <BR>
<P> /* get file name */ <BR> printf("Enter drive
and file name (no path - ie. a:file.dat)\n"); <BR> gets(line);
<BR>
<P> /* put file name in fcb */ <BR> if
(parsfnm(line, &blk, 1) == NULL) <BR>
printf("Error in parsfm call\n"); <BR> else
<BR> printf("Drive #%d Name: %11s\n",
blk.fcb_drive, blk.fcb_name); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: peek <BR>功 能: 检查存储单元 <BR>用 法: int peek(int segment,
unsigned offset); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <conio.h> <BR>#include
<dos.h> <BR>
<P>int main(void) <BR>{ <BR> int value = 0; <BR>
<P> printf("The current status of your keyboard is:\n");
<BR> value = peek(0x0040, 0x0017); <BR> if (value
& 1) <BR> printf("Right shift on\n");
<BR> else <BR> printf("Right
shift off\n"); <BR>
<P> if (value & 2) <BR>
printf("Left shift on\n"); <BR> else
<BR> printf("Left shift off\n"); <BR>
<P> if (value & 4) <BR>
printf("Control key on\n"); <BR> else
<BR> printf("Control key off\n"); <BR>
<P> if (value & 8) <BR>
printf("Alt key on\n"); <BR> else
<BR> printf("Alt key off\n"); <BR>
<P> if (value & 16) <BR>
printf("Scroll lock on\n"); <BR> else
<BR> printf("Scroll lock off\n"); <BR>
<P> if (value & 32) <BR>
printf("Num lock on\n"); <BR> else
<BR> printf("Num lock off\n"); <BR>
<P> if (value & 64) <BR>
printf("Caps lock on\n"); <BR> else
<BR> printf("Caps lock off\n"); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: peekb <BR>功 能: 检查存储单元 <BR>用 法: char peekb (int
segment, unsigned offset); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <conio.h> <BR>#include
<dos.h> <BR>
<P>int main(void) <BR>{ <BR> int value = 0; <BR>
<P> printf("The current status of your keyboard is:\n");
<BR> value = peekb(0x0040, 0x0017); <BR> if (value
& 1) <BR> printf("Right shift on\n");
<BR> else <BR> printf("Right
shift off\n"); <BR>
<P> if (value & 2) <BR>
printf("Left shift on\n"); <BR> else
<BR> printf("Left shift off\n"); <BR>
<P> if (value & 4) <BR>
printf("Control key on\n"); <BR> else
<BR> printf("Control key off\n"); <BR>
<P> if (value & 8) <BR>
printf("Alt key on\n"); <BR> else
<BR> printf("Alt key off\n"); <BR>
<P> if (value & 16) <BR>
printf("Scroll lock on\n"); <BR> else
<BR> printf("Scroll lock off\n"); <BR>
<P> if (value & 32) <BR>
printf("Num lock on\n"); <BR> else
<BR> printf("Num lock off\n"); <BR>
<P> if (value & 64) <BR>
printf("Caps lock on\n"); <BR> else
<BR> printf("Caps lock off\n"); <BR>
<P> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: perror <BR>功 能: 系统错误信息 <BR>用 法: void perror(char
*string); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> FILE *fp; <BR>
<P> fp = fopen("perror.dat", "r"); <BR> if (!fp)
<BR> perror("Unable to open file for
reading"); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: pieslice <BR>功 能: 绘制并填充一个扇形 <BR>用 法: void far
pieslice(int x, int stanle, int endangle, int radius); <BR>程序例: <BR>
<P>#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, radius
= 100; <BR>
<P> /* initialize graphics and local variables */
<BR> initgraph(&gdriver, &gmode, ""); <BR>
<P> /* 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> } <BR>
<P> midx = getmaxx() / 2; <BR> midy = getmaxy() /
2; <BR>
<P> /* set fill style and draw a pie slice */ <BR>
setfillstyle(EMPTY_FILL, getmaxcolor()); <BR> pieslice(midx,
midy, stangle, endangle, radius); <BR>
<P> /* clean up */ <BR> getch(); <BR>
closegraph(); <BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: poke <BR>功 能: 存值到一个给定存储单元 <BR>用 法: void poke(int
segment, int offset, int value); <BR>程序例: <BR>
<P>#include <dos.h> <BR>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> clrscr(); <BR>
cprintf("Make sure the scroll lock key is off and press any key\r\n");
<BR> getch(); <BR> poke(0x0000,0x0417,16);
<BR> cprintf("The scroll lock is now on\r\n");
<BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: pokeb <BR>功 能: 存值到一个给定存储单元 <BR>用 法: void pokeb(int
segment, int offset, char value); <BR>程序例: <BR>
<P>#include <dos.h> <BR>#include <conio.h> <BR>
<P>int main(void) <BR>{ <BR> clrscr(); <BR>
cprintf("Make sure the scroll lock key is off and press any key\r\n");
<BR> getch(); <BR> pokeb(0x0000,0x0417,16);
<BR> cprintf("The scroll lock is now on\r\n");
<BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: poly <BR>功 能: 根据参数产生一个多项式 <BR>用 法: double poly(double
x, int n, double c[]); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <math.h> <BR>
<P>/* polynomial: x**3 - 2x**2 + 5x - 1 */ <BR>
<P>int main(void) <BR>{ <BR> double array[] = { -1.0, 5.0,
-2.0, 1.0 }; <BR> double result; <BR>
<P> result = poly(2.0, 3, array); <BR> printf("The
polynomial: x**3 - 2.0x**2 + 5x - 1 at 2.0 is %lf\n",
<BR> result);
<BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: pow <BR>功 能: 指数函数(x的y次方) <BR>用 法: double pow(double x,
double y); <BR>程序例: <BR>
<P>#include <math.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> double x = 2.0, y = 3.0; <BR>
<P> printf("%lf raised to %lf is %lf\n", x, y, pow(x, y));
<BR> return 0; <BR>} <BR> <BR>
<P>函数名: pow10 <BR>功 能: 指数函数(10的p次方) <BR>用 法: double pow10(int
p); <BR>程序例: <BR>
<P>#include <math.h> <BR>#include <stdio.h> <BR>
<P>int main(void) <BR>{ <BR> double p = 3.0; <BR>
<P> printf("Ten raised to %lf is %lf\n", p, pow10(p));
<BR> return 0; <BR>} <BR> <BR> <BR>
<P>函数名: printf <BR>功 能: 产生格式化输出的函数 <BR>用 法: int printf(char
*format...); <BR>程序例: <BR>
<P>#include <stdio.h> <BR>#include <string.h> <BR>
<P>#define I 555 <BR>#define R 5.5 <BR>
<P>int main(void) <BR>{ <BR> int i,j,k,l; <BR>
char buf[7]; <BR> char *prefix = buf; <BR> char
tp[20]; <BR> printf("prefix
6d 6o
8x
10.2e "
<BR> "10.2f\n");
<BR> strcpy(prefix,"%"); <BR> for (i = 0; i <
2; i++) <BR> { <BR> for (j = 0;
j < 2; j++) <BR> for (k
= 0; k < 2; k++) <BR> for (l = 0; l < 2;
l++)
<BR> {
<BR>
if (i==0) strcat(prefix,"-");
<BR>
if (j==0) strcat(prefix,"+");
<BR>
if (k==0) strcat(prefix,"#");
<BR>
if (l==0) strcat(prefix,"0");
<BR>
printf("%5s |",prefix);
<BR>
strcpy(tp,prefix);
<BR>
strcat(tp,"6d |");
<BR>
printf(tp,I);
<BR>
strcpy(tp,"");
<BR>
strcpy(tp,prefix);
<BR>
strcat(tp,"6o |");
<BR>
printf(tp,I);
<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -