1、C语言函数大全p开头docx函数大全(p开头)61函数名:parsfnm功能:分析文件名用 法:char *parsfnm (char *cmdline, struct fcb *fcbptr, int option); 程序例:#include #include #include #include int main(void)char line80;struct fcb blk;/* get file name */printf(MEnter drive and file name (no path - ie. a:file.dat)nM); gets(line);/* put file n
2、ame in fcb */if (parsfnm(line, &blk, 1) = NULL)printf(MError in parsfm callnH);elseprintf(Drive #%d Name: %1 lsn, blk.fcb_drive, blk.fcb_name);return 0;函数名:peek功能:检查存储单元用 法:int peek(int segment, unsigned offset); 程序例:#include #include #include int main(void)int value = 0;prinif(=The current sUHus of
3、 your keyboard is,n=); value H Peek(oxoo4p0x0017)八 if (value 1)PS-二 f(-Right shift onm=)八elseprintaRight shift 05n=)八if (value 2)primf(=Lefr shift onvr.relseprin-fTLen shift O51T);if (value &. 4) printf(=con=rol key onn=)_elseprin.s=co=ro】 key offn=)八if (valueRp8)printf(=Alr key onn=)一elseprins-t ke
4、y 03=)if (vace 8l 16) prinf(=scro=ock 02n=relse primf(=scro=ock offn=);if (vace 8c 32) primf(=Num lock onn=);else prinif(=Numock offn=);if (vace 8l 64)primacaps lock onw);elseprimf(二capsock 03=)rerun-p因磬Ik【peekb功能:检查存储单元用 法:char peekb (int segment, unsigned offset); 程序例:#include #include #include in
5、t main(void)int value = 0;printf(The current status of your keyboard is:n); value = peekb(0x0040, 0x0017);if (value & 1)printf(Right shift onn);elseprintf(MRight shift offnM);if (value & 2)printf(Left shift onn);elseprintf(Left shift offnH);if (value & 4)printf(Control key onnH);elseprintf(Control k
6、ey offn);if (value & 8)printf(Alt key onn);elseprintf(Alt key oflAn);if (value & 16)printf(Scroll lock onnu);elseprintfCScroll lock offn,f);if (value & 32)printfCNum lock onnu);elseprintf(Num lock offnu);if (value & 64) printfCCaps lock onn);elseprintf(HCaps lock offn);return 0;函数名:perror功能:系统错误信息用
7、法:void perror(char string);程序例:#include int main(void)FILE *fp;fp = fopen(peiTor.dat r);perror(HUnable to open file for reading0); return 0;函数名:pieslice功能:绘制并填充一个扇形用 法:void far pieslice(int x, int stanle, int endangle, int radius); 程序例:#include #include #include #include int main(void)/* request aut
8、o detection */int gdriver = DETECT, gmode, errorcode;int midx, midy;int stangle = 45, endangle = 135, radius = 100;/* initialize graphics and local variables */ initgraph(&gdriver, &gmode,HH);/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */p
9、rintf(HGraphics error: %snH, grapheiTormsg(errorcode); printf(nPress any key to halt:H);getch();exit(l); /* terminate with an error code */midx = getmaxx() / 2; midy = getmaxy() / 2;/* set fill style and draw a pie slice */ setfillstyle(EMPTY_FILL, getmaxcolor(); pieslice(midx, midy, stangle, endang
10、le, radius);/* clean up */ getch(); closegraph(); return 0;函数名:poke功能:存值到一个给定存储单元用 法:void poke(int segment, int offset, int value);程序例:#include #include int main(void)clrscr();cprintf(nMake sure the scroll lock key is off and press any keyrnH); getch();poke(0x0000,0x0417,16);cprintf(nThe scroll lock
11、 is now onrnH); return 0;函数名:pokeb功能:存值到一个给定存储单元用 法:void pokeb(int segment, int offset, char value);程序例:#include #include int main(void)clrscr();cprintf(HMake sure the scroll lock key is off and press any keyrnH); getch();pokeb(0x0000,0x0417,16);cprintf(nThe scroll lock is now onrnM);return 0;函数名:po
12、ly功能:根据参数产生一个多项式用 法:double poly(double x, int n, double cJ);程序例:#include #include /* polynomial: x*3 2x*2 + 5x 1 */int main(void)double array = -1.0, 5.0, -2.0, 1.0 ;double result;result = poly(2.0, 3, array);printf(The polynomial: x*3 - 2.0x*2 + 5x - 1 at 2.0 is %lfn, result);return 0;函数名:pow功 能:指数
13、函数(x的y次方)用 法:double pow(double x, double y);程序例:#include #include int main(void)double x = 2.0, y = 3.0;printf(%lf raised to %lf is x, y, pow(x, y);return 0;函数名:pow 10功能:指数函数(10的p次方) 用 法:double powl0(int p);程序例:#include #inelude int main(void)double p = 3.0;printf(MTen raised to %lf is %lfnH, p, pow
14、lO(p); return 0;函数名:printf功能:产生格式化输出的函数 用 法:int printf(char *format); 程序例:#include #include #define I 555#define R 5.5int main(void)int i,j,k,l;char buf71;char prefix = buf;char tp20;printf(Mprefix 6d 60 8x 10.2e”10.22”);strcpy(prefix,%n);for (i = 0; i 2; i+)for(j = 0;j2;j+)for (k = 0; k 2; k+)for (
15、1 = 0; 1 2; 1+)if (i=0) strcat(prefix,H-H);讦(j=0) strcat(prefix,H+n);if (k=0) strcat(prefix,*#);if (l=0) strcat(prefix,HOM); printf(%5s |u,prefix); strcpy(tp,prefix);strcat(tp/6d printf(tp,I); strcpy(tp;M,);strcpy(tp,prefix);strcat(tp;6o |H); printf(tp,I);strcpy(tp;n,); strcpy(tp,prefix);strcat(tp,8
16、x printf(tp,I);strcpy(tp;,H); strcpy(tp,prefix);strcat(tp,10.2e printf(tp,R);strcpy(tp,prefix);strcat(tp,”10.2iT);printf(tp,R); printfC nH); strcpy(prefix/%);)return 0;函数名:putc功能:输出一字符到指定流中用 法:int putc(int ch, FILE * stream); 程序例:#include int main(void)char msg = MHello worldnH;int i = 0;while (msgi
17、)putc(msgi+, stdout);return 0;函数名:putch功能:输出字符到控制台 用 法:int putch(int ch);程序例:#include #include int main(void)char ch = 0;printf(MInput a string:”); while (ch != V) ch = getch(); putch(ch);return 0;函数名:putchar功能:在stdout 输出字符用 法:int putchar(int ch);程序例:#include /* define some box-drawing characters */
18、#define LEFT_TOP OxDA#define RIGHT_TOP OxBF#define HORIZ 0xC4#define VERT 0xB3#define LEFT.BOT OxCO#define RIGHT.BOT 0xD9int main(void)char i, j;/* draw the top of the box */ putchar(LEFT_TOP);for (i=0; i10; i+)putchar(HORIZ);putchar(RIGHT_TOP); putcharCn);/* draw the middle */for (i=0; i4; i+)putch
19、ar(VERT); for(j=0;j10;j+)putchar();putchar(VERT);putchar(n);/* draw the bottom */ putchar(LEFT_BOT); for (i=0; i10; i+) putchar(HORIZ);putchar(RIGHT_BOT); putchar(n);return 0;函数名:putenv功能:把字符串加到当前环境中用 法:int putenv(char *envvar);程序例:#include #include #include #include #include int main(void)char *pat
20、h, *ptr;int i = 0;/* get the current path envionment */ptr = getenv(PATHM);/* set up new path /path = malloc(strlen(ptr)+15);strcpy(path,MPATH=M);strcat(path,ptr);strcat(path/,;c:tempu);/* replace the current path and display current environment */ putenv(path);while (environi)printf(%sn,environfi+)
21、;return 0;函数名:put image功能:在屏幕上输出一个位图用 了去:void far putimage(int x, int y, void far bitmap, int op); 程序例:#inelude #include #include #include #define ARROW_S1ZE 10 void draw_arrow(int x, int y);int main(void)/* request autodetection */int gdriver = DETECT, gmode, errorcode;void * arrow;int x, y, maxx;u
22、nsigned int size;/* initialize graphics and local variables */initgraph(&gdrivei &gmode,HU);/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */printf(nGraphics error: %snM, grapheiTormsg(errorcode); printf(HPress any key to halt:”);getch();exit
23、(l); /* terminate with an error code */maxx = getmaxx();x = 0;y = getmaxyO / 2;/* draw the image to be grabbed */draw_arrow(x, y);/* calculate the size of the image */size = imagesize(x, y-ARROW_SIZE, x+(4*ARR0W_SIZE), y+ARROW_SIZE);/* allocate memory to hold the image */arrow = malloc(size);/* grab
24、 the image */getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, arrow);/* repeat until a key is pressed */while (!kbhit()/* erase old image */putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);x += ARROW_SIZE;if (x = maxx)x = 0;/* plot new image */putimage(x, y-ARROW_SIZE, arrow, XOR_PUT);/* clean up
25、*/ free(aiTow); closegraph(); return 0;void draw_arrow(int x, int y)/* draw an arrow on the screen */ moveto(x, y);linerel(4*ARROW_SIZE, 0);linerel(-2*ARROW_SIZE, -1 *ARROW_SIZE); linereKO, 2*ARROW_SIZE);linerel(2*ARROW_SIZE, -1 *ARROW_SIZE);函数名:putpixel功能:在指定位置画一像素 用 法:void far putpixel (int x, int
26、 y, int pixelcolor); 程序例:#inelude #include #include #include #include #define PIXEL_COUNT 1000#define DELAY TIME 100 /* in milliseconds */ int main(void)/* request autodetection */int gdriver = DETECT, gmode, errorcode;int i, x, y, color, maxx, maxy, maxcolor, seed;/* initialize graphics and local v
27、ariables */initgraph(&gdriver, &gmode,HU);/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */printf(nGraphics error: %sn grapheiTormsg(errorcode); printf(HPress any key to halt:11);getch();exit(l); /* terminate with an error code */maxx = getma
28、xx() + 1;maxy = getmaxy() + 1;maxcolor = getmaxcolor() + 1;while (!kbhit()/* seed the random number generator */seed = ran dom(32767);srand(seed);for (i=0; iPIXEL_COUNT; i+)x = random(maxx);y = ran dom(niaxy);color = random(maxcolor); putpixel(x, y, color);delay(DELAY_TIME); srand(seed);for (i=0; iPIXEL_COUNT; i+) x = ran dom(maxx);y = random(maxy);color = random(maxcolor);if (color = getpixel(x, y) putpixel(x, y, 0);/* clean up */ getch(); closegraph(); return 0;函数名:puts功能:送一字符串
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1