C语言函数大全(p开头).docx.pdf

上传人:tbuqq 文档编号:5615860 上传时间:2020-07-02 格式:PDF 页数:17 大小:317.82KB
返回 下载 相关 举报
C语言函数大全(p开头).docx.pdf_第1页
第1页 / 共17页
C语言函数大全(p开头).docx.pdf_第2页
第2页 / 共17页
C语言函数大全(p开头).docx.pdf_第3页
第3页 / 共17页
C语言函数大全(p开头).docx.pdf_第4页
第4页 / 共17页
C语言函数大全(p开头).docx.pdf_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《C语言函数大全(p开头).docx.pdf》由会员分享,可在线阅读,更多相关《C语言函数大全(p开头).docx.pdf(17页珍藏版)》请在三一文库上搜索。

1、函数大全 (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( M Enter drive and file name (no path - ie. a:file.dat)n M ); gets(line); /* put fi

2、le name in fcb */ if (parsfnm(line, else printf(“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 your keyboard is,n=) ; value H

3、 Peek(oxoo4p0x0017) 八 if (value 1) P S- 二 f(-Right shift onm=) 八 else printaRight shift 0 5 n = ) 八 if (value 2) primf(=Lefr shift onvr.r else prin-fTLen shift O 5 1 T ) ; if (value 程序例: #include #include #include int main(void) int value = 0; printf(“The current status of your keyboard is:n“); valu

4、e = peekb(0x0040, 0x0017); if (value else printf( M Right shift offn M ); if (value else printf(“Left shift offn H); if (value else printf(“Control key offn“); if (value else printf(“Alt key oflAn“); if (value else printfCScroll lock offn ,f ); if (value else printf(“Num lock offn u); if (value else

5、 printf( HCaps lock offn“); return 0; 函数名: perror 功能:系统错误信息 用 法:void perror(char string); 程序例: #include int main(void) FILE *fp; fp = fopen(“peiTor.dat “r“); perror(HUnable to open file for reading 0); return 0; 函数名: pieslice 功能: 绘制并填充一个扇形 用 法: void far pieslice(int x, int stanle, int endangle, int

6、radius); 程序 例: #include #include #include #include int main(void) /* request auto detection */ int gdriver = DETECT, gmode, errorcode; int midx, midy; int stangle = 45, endangle = 135, radius = 100; /* initialize graphics and local variables */ initgraph( /* read result of initialization */ errorcod

7、e = graphresult(); if (errorcode != grOk) /* an error occurred */ printf( 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 */ set

8、fillstyle(EMPTY_FILL, getmaxcolor(); pieslice(midx, midy, stangle, endangle, 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

9、is off and press any keyrnH); getch(); poke(0x0000,0x0417,16); cprintf( nThe scroll lock 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 a

10、ny keyrnH); getch(); pokeb(0x0000,0x0417,16); cprintf( nThe scroll lock is now onrnM ); return 0; 函数名: poly 功能: 根据参数产生一个多项式 用 法: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; re

11、sult = poly(2.0, 3, array); printf(“The polynomial: x*3 - 2.0x*2 + 5x - 1 at 2.0 is %lfn“, result); return 0; 函数名: pow 功 能: 指数函数 (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; 函数名:

12、 pow 10 功能: 指数函数 (10的 p次方 ) 用 法: double powl0(int p); 程序例: #include #inelude int main(void) double p = 3.0; printf( M Ten raised to %lf is %lfn H, p, powlO(p); return 0; 函数名: printf 功能: 产生格式化输出的函数用 法: int printf(char *format ); 程序 例: #include #include #define I 555 #define R 5.5 int main(void) int i

13、,j,k,l; char buf71; char prefix = buf; char tp20; printf( M prefix 6d 60 8x 10.2e ”10.22 ”); strcpy(prefix,“% n); for (i = 0; i int main(void) char msg = M Hello worldn H; int i = 0; while (msgi) putc(msgi+, stdout); return 0; 函数名: putch 功能: 输出字符到控制台用 法:int putch(int ch); 程序例: #include #include int

14、main(void) char ch = 0; printf( M Input a string:”); while (ch != V) ch = getch(); putch(ch); return 0; 函数名: putchar 功能: 在 stdout 输出字符 用 法:int putchar(int ch); 程序例: #include /* define some box-drawing characters */ #define LEFT_TOP OxDA #define RIGHT_TOP OxBF #define HORIZ 0xC4 #define VERT 0xB3 #de

15、fine LEFT.BOT OxCO #define RIGHT.BOT 0xD9 int main(void) char i, j; /* draw the top of the box */ putchar(LEFT_TOP); for (i=0; i #include #include #include #include int main(void) char *path, *ptr; int i = 0; /* get the current path envionment */ ptr = getenv(“PATH M ); /* set up new path ?/ path =

16、malloc(strlen(ptr)+15); strcpy(path, M PATH= M ); strcat(path,ptr); strcat(path/ ,;c:tempu); /* replace the current path and display current environment */ putenv(path); while (environi) printf(“%sn“,environfi+); return 0; 函数名: put image 功能: 在屏幕上输出一个位图 用 了去: void far putimage(int x, int y, void far

17、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; unsigned int size; /* initialize graphics and local variables */ initgraph(

18、/* 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(l); /* terminate with an error code */ maxx = getmaxx(); x = 0; y = getmaxyO / 2;

19、/* 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 the image */ getimage(x, y-ARROW_SIZE, x+(4*ARROW_SIZE), y+ARROW_SIZE, a

20、rrow); /* 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 */ free(aiTow); closegraph(); return 0; void draw_arrow(int x,

21、 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 y, int pixelcolor); 程序 例: #inelude #include #include

22、 #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 variables */ initgraph( /* read result of initi

23、alization */ 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 = getmaxx() + 1; maxy = getmaxy() + 1; maxcolor = getmaxcolor()

24、+ 1; while (!kbhit() /* seed the random number generator */ seed = ran dom(32767); srand(seed); for (i=0; i int main(void) char string = This is an example output stringn M ; puts(string); return 0; 函数名: puttext 功能: 将文本从存储区拷贝到屏幕 用 法: int puttext(int left, int top, int right, int bottom, void *source

25、); 程序例: #include int main(void) char buffer512J; /* put some text to the console */ clrscr(); gotoxy(20, 12); cprintf( uThis is a test. Press any key to continue getch(); /* grab screen contents */ gettext(20, 12, 36, 21,buffer); clrscr(); /* put selected characters back to the screen */ gotoxy(20,

26、12); puttext(20, 12, 36, 21, buffer); getch(); return 0; 函数名: putw 功能: 把一字符或字送到流中 用 法: int putw(int w, FILE *stream); 程序例: #include #include #define FNAME ntest.$H int main(void) FILE *fp; int word; /* place the word in a file */ fp = fopen(FNAME, nwbu); if( fp=NULL) printf(“Error opening file %sn“,

27、 FNAME); exit(l); word = 94; putw(word,fp); if (ferror(fp) printf(“Error writing to filen“); else printf(“Successful writen u); fclose(fp); /* reopen the file */ fp = fopen(FNAME, M rbM); if (fp = NULL) printfCEnor opening file %sn“, FNAME); exit(l); 1 /* extract the word */ word = getw(fp); if (ferror(fp) printf(“EiTor reading filen“); else printf( HSuccessful read: word = %dnf word); /* clean up */ fclose(fp); unlink(FNAME); return 0;

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1