C语言函数大全(p开头).docx
c语言常用函数大全超详细

c语言常用函数大全超详细C语言常用函数大全:A Comprehensive Guide in ChineseC语言是一种非常流行且广泛应用的编程语言,其提供了许多内置函数来处理各种任务。
在本文中,我们将详细介绍一些C语言常用的函数,以帮助初学者和有经验的程序员更好地理解和应用这些函数。
1. printf()函数:该函数用于输出文本到屏幕或文件。
使用格式化字符串可以实现不同类型的输出,如整数、浮点数和字符串。
2. scanf()函数:该函数用于从用户输入中读取数据,并将其保存到变量中。
和printf()函数一样,scanf()函数也使用格式化字符串来指定输入的数据类型。
3. strlen()函数:该函数用于计算字符串的长度。
它返回一个无符号整数,表示字符串中字符的数量,不包括空结束符。
4. strcpy()函数:该函数用于将一个字符串复制到另一个字符串。
它将源字符串中的字符复制到目标字符串中,并在目标字符串的末尾添加空结束符。
5. strcat()函数:该函数用于将一个字符串连接到另一个字符串的末尾。
它将源字符串中的字符连接到目标字符串的末尾,并确保目标字符串以空结束符结尾。
6. atoi()函数:该函数将一个字符串转换为整数并返回结果。
7. atof()函数:该函数将一个字符串转换为浮点数并返回结果。
8. srand()函数:该函数用于初始化随机数生成器。
通过提供一个种子值,可以生成伪随机数序列。
9. rand()函数:该函数生成一个伪随机数。
在调用srand()函数之后,可以使用rand()函数来获取一系列不同的随机数。
10. fopen()函数:该函数用于打开文件,并返回一个指向该文件的指针。
可以指定不同的模式来进行读取、写入或同时读写文件。
11. fclose()函数:该函数用于关闭已经打开的文件。
在完成文件操作后调用该函数是一个良好的编程实践,以确保文件资源被正确释放。
12. fgets()函数:该函数用于从文件中读取一行文本。
C语言函数大全

Turbo C函数alloc.hbrk【功能】更改数据段空间的分配【原型】int brk(void *endds)【位置】alloc.h【说明】将程序数据段的顶部设置为endds所指向的内存位置。
调用成功之后,返回0。
如果调用失败则返回-1,同时设置errno。
【参见】coreleftcalloc【功能】分配内存。
【原型】void *calloc(size_t nelem,size_t elsize)【位置】stdib.h,alloc.h【说明】为nelem数据项的每elsize个字节分别分配空间,同时在空间中保存0值。
返回一个指向新分配块的指针,如果没有足够的空间则返回NULL。
【参见】malloccoreleft【功能】返回测出的未使用内存量。
【原型】小型模块中unsigend long coreleft(void)【位置】alloc.h【参见】mallocfarcallc【功能】从高端开始分配内存。
【原型】void far *farcalloc(unsigned ling nunits,unsigned ling unitsz)【位置】alloc.h【说明】为nunits数据项的每unitsz个字节分配空间。
返回指向新分配块的指针,如果没有足够的空间创建数据块,则返回NULL【参见】farmalloc,farfree,farcoreleft,malloc,callocfarcoreleft【功能】返回测出的高端未使用内存量。
【原型】unsigned long farcoreleft(void)【位置】alloc.h【说明】返回最高分配数据块和内存末端之间所剩的所有空间量(按照字节计算)。
【参见】farcalloc,farmalloc,coreleftfarfree【功能】从高端释放一个数据块。
【原型】void farfree(void far *block)【位置】alloc【参见】farmalloc,farcallocfarmalloc【功能】从高端开始分配。
(完整版)C语言函数大全

功能: 异常终止一个进程用法: void abort(void)函数名: abs功能: 求整数的绝对值用法: int abs(int i)函数名: absread, abswirte功能: 绝对磁盘扇区读、写数据用法: int absread(int drive, int nsects, int sectno, void *buffer) int abswrite(int drive, int nsects, in tsectno, void *buffer函数名: access功能: 确定文件的访问权限用法: int access(const char *filename, int amode)函数名: acos功能:反余弦函数用法: double acos(double x)函数名: allocmem功能: 分配DOS存储段用法:int allocmem(unsigned size, unsigned *seg)函数名: arc功能: 画一弧线用法:void far arc(int x, int y, int stangle, int endangle, int radius)函数名: asctime功能: 转换日期和时间为ASCII码用法:char *asctime(const struct tm *tblock)函数名: asin功能:反正弦函数用法: double asin(double x)函数名: assert功能: 测试一个条件并可能使程序终止用法:void assert(int test)函数名: atan功能: 反正切函数用法: double atan(double x)功能: 计算Y/X的反正切值用法: double atan2(double y, double x)函数名:atexit功能: 注册终止函数用法: int atexit(atexit_t func)函数名: atof功能: 把字符串转换成浮点数用法:double atof(const char *nptr)函数名: atoi功能: 把字符串转换成长整型数用法: int atoi(const char *nptr)函数名: atol功能: 把字符串转换成长整型数用法: long atol(const char *nptr)函数名: bar功能: 画一个二维条形图用法: void far bar(int left, int top, int right, int bottom)函数名: bar3d功能: 画一个三维条形图用法:void far bar3d(int left, int top, int right, int bottom,int depth, int topflag)函数名: bdos功能: DOS系统调用用法: int bdos(int dosfun, unsigned dosdx, unsigned dosal)函数名:bdosptr功能:DOS系统调用用法: int bdosptr(int dosfun, void *argument, unsigned dosal)函数名:bioscom功能: 串行I/O通信用法:int bioscom(int cmd, char abyte, int port)函数名:biosdisk功能: 软硬盘I/O用法:int biosdisk(int cmd, int drive, int head, int track, int sectorint nsects, void *buffer)函数名:biosequip功能: 检查设备用法:int biosequip(void)函数名:bioskey功能: 直接使用BIOS服务的键盘接口用法:int bioskey(int cmd)函数名:biosmemory功能: 返回存储块大小用法:int biosmemory(void)函数名:biosprint功能: 直接使用BIOS服务的打印机I/O用法:int biosprint(int cmd, int byte, int port)函数名:biostime功能: 读取或设置BIOS时间用法: long biostime(int cmd, long newtime)函数名: brk功能: 改变数据段空间分配用法:int brk(void *endds)函数名:bsearch功能: 二分法搜索用法:void *bsearch(const void *key, const void *base, size_t *nelem, size_t width, int(*fcmp)(const void *, const *))函数名: cabs功能: 计算复数的绝对值用法: double cabs(struct complex z);函数名:calloc功能:分配主存储器用法:void *calloc(size_t nelem, size_t elsize);函数名: ceil功能: 向上舍入用法: double ceil(double x);函数名: cgets功能: 从控制台读字符串用法: char *cgets(char *str)函数名:chdir功能: 改变工作目录用法: int chdir(const char *path);函数名:_chmod, chmod功能: 改变文件的访问方式用法: int chmod(const char *filename, int permiss);函数名:chsize功能: 改变文件大小用法: int chsize(int handle, long size);函数名: circle功能: 在给定半径以(x, y)为圆心画圆用法: void far circle(int x, int y, int radius);函数名: cleardevice功能: 清除图形屏幕用法: void far cleardevice(void);函数名:clearerr功能: 复位错误标志用法:void clearerr(FILE *stream);函数名: clearviewport功能: 清除图形视区用法: void far clearviewport(void);函数名:_close, close功能: 关闭文件句柄用法:int close(int handle);函数名: clock功能:确定处理器时间用法: clock_t clock(void);函数名:closegraph功能: 关闭图形系统用法: void far closegraph(void);函数名:clreol功能: 在文本窗口中清除字符到行末用法:void clreol(void)函数名:clrscr功能: 清除文本模式窗口用法:void clrscr(void);函数名: coreleft功能: 返回未使用内存的大小用法:unsigned coreleft(void);函数名: cos功能: 余弦函数用法:double cos(double x);函数名:cosh功能: 双曲余弦函数用法: dluble cosh(double x);函数名: country功能: 返回与国家有关的信息用法: struct COUNTRY *country(int countrycode, struct country *country); 函数名: cprintf功能: 送格式化输出至屏幕用法:int cprintf(const char *format[, argument, ...]);函数名: cputs功能: 写字符到屏幕用法: void cputs(const char *string);函数名: _creat creat功能: 创建一个新文件或重写一个已存在的文件用法: int creat (const char *filename, int permiss)函数名:creatnew功能: 创建一个新文件用法:int creatnew(const char *filename, int attrib);函数名: cscanf功能: 从控制台执行格式化输入用法:int cscanf(char *format[,argument, ...]);函数名: ctime功能: 把日期和时间转换为字符串用法:char *ctime(const time_t *time);功能: 设置Ctrl-Break处理程序用法: void ctrlbrk(*fptr)(void);函数名: delay功能: 将程序的执行暂停一段时间(毫秒)用法: void delay(unsigned milliseconds);函数名: delline功能: 在文本窗口中删去一行用法: void delline(void);函数名:detectgraph功能: 通过检测硬件确定图形驱动程序和模式用法: void far detectgraph(int far *graphdriver, int far *graphmode); 函数名: difftime功能: 计算两个时刻之间的时间差用法: double difftime(time_t time2, time_t time1);函数名: disable功能: 屏蔽中断用法:void disable(void);函数名: div功能: 将两个整数相除, 返回商和余数用法:div_t (int number, int denom);函数名: dosexterr功能: 获取扩展DOS错误信息用法:int dosexterr(struct DOSERR *dblkp);函数名: dostounix功能: 转换日期和时间为UNIX时间格式用法: long dostounix(struct date *dateptr, struct time *timeptr);函数名: drawpoly功能: 画多边形用法: void far drawpoly(int numpoints, int far *polypoints);函数名:dup功能: 复制一个文件句柄用法: int dup(int handle);函数名:dup2功能: 复制文件句柄用法: int dup2(int oldhandle, int newhandle);功能: 把一个浮点数转换为字符串用法: char ecvt(double value, int ndigit, int *decpt, int *sign);函数名: ellipse功能: 画一椭圆用法:void far ellipse(int x, int y, int stangle, int endangle,int xradius, int yradius);函数名: enable功能: 开放硬件中断用法: void enable(void);函数名: eof功能: 检测文件结束用法: int eof(int *handle);函数名: exec...功能: 装入并运行其它程序的函数用法: int execl(char *pathname, char *arg0, arg1, ..., argn, NULL); int execle(char *pathname, char *arg0, arg1, ..., argn, NULL,char *envp[]);int execlp(char *pathname, char *arg0, arg1, .., NULL);int execple(char *pathname, char *arg0, arg1, ..., NULL,char *envp[]);int execv(char *pathname, char *argv[]);int execve(char *pathname, char *argv[], char *envp[]);int execvp(char *pathname, char *argv[]);int execvpe(char *pathname, char *argv[], char *envp[]);函数名:exit功能: 终止程序用法: void exit(int status);函数名: exp功能: 指数函数用法: double exp(double x);函数名: gcvt功能: 把浮点数转换成字符串用法: char *gcvt(double value, int ndigit, char *buf);函数名: geninterrupt功能: 产生一个软中断函数名: getarccoords功能: 取得最后一次调用arc的坐标用法: void far getarccoords(struct arccoordstype far *arccoords); 函数名: getaspectratio功能: 返回当前图形模式的纵横比用法: void far getaspectratio(int far *xasp, int far *yasp);函数名: getbkcolor功能: 返回当前背景颜色用法: int far getbkcolor(void);函数名: getc功能: 从流中取字符用法: int getc(FILE *stream);函数名: getcbrk功能: 获取Control_break设置用法: int getcbrk(void);函数名: getch功能: 从控制台无回显地取一个字符用法: int getch(void);函数名: getchar功能: 从stdin流中读字符用法: int getchar(void);函数名: getche功能: 从控制台取字符(带回显)用法: int getche(void);函数名: getcolor功能: 返回当前画线颜色用法: int far getcolor(void);函数名: getcurdir功能: 取指定驱动器的当前目录用法: int getcurdir(int drive, char *direc);函数名: getcwd功能: 取当前工作目录用法: char *getcwd(char *buf, int n);函数名: getdate功能: 取DOS日期函数名: getdefaultpalette功能: 返回调色板定义结构用法: struct palettetype *far getdefaultpalette(void);函数名: getdisk功能: 取当前磁盘驱动器号用法: int getdisk(void);函数名: getdrivername功能: 返回指向包含当前图形驱动程序名字的字符串指针用法: char *getdrivename(void);函数名: getdta功能: 取磁盘传输地址用法: char far *getdta(void);函数名: getenv功能: 从环境中取字符串用法: char *getenv(char *envvar);函数名: getfat, getfatd功能: 取文件分配表信息用法: void getfat(int drive, struct fatinfo *fatblkp);函数名: getfillpattern功能: 将用户定义的填充模式拷贝到内存中用法: void far getfillpattern(char far *upattern);函数名: getfillsettings功能: 取得有关当前填充模式和填充颜色的信息用法: void far getfillsettings(struct fillsettingstype far *fillinfo); 函数名: getftime功能: 取文件日期和时间用法: int getftime(int handle, struct ftime *ftimep);函数名: getgraphmode功能: 返回当前图形模式用法: int far getgraphmode(void);函数名: getftime功能: 取文件日期和时间用法: int getftime(int handle, struct ftime *ftimep);函数名: getgraphmode功能: 返回当前图形模式用法: int far getgraphmode(void);函数名: getimage功能: 将指定区域的一个位图存到主存中用法: void far getimage(int left, int top, int right, int bottom,void far *bitmap);函数名: getlinesettings功能: 取当前线型、模式和宽度用法: void far getlinesettings(struct linesettingstype far *lininfo): 函数名: getmaxx功能: 返回屏幕的最大x坐标用法: int far getmaxx(void);函数名: getmaxy功能: 返回屏幕的最大y坐标用法: int far getmaxy(void);函数名: getmodename功能: 返回含有指定图形模式名的字符串指针用法: char *far getmodename(int mode_name);函数名: getmoderange功能: 取给定图形驱动程序的模式范围用法: void far getmoderange(int graphdriver, int far *lomode,int far *himode);函数名: getpalette功能: 返回有关当前调色板的信息用法: void far getpalette(struct palettetype far *palette);函数名: getpass功能: 读一个口令用法: char *getpass(char *prompt);函数名: getpixel功能: 取得指定像素的颜色用法: int far getpixel(int x, int y);函数名: gets功能: 从流中取一字符串用法: char *gets(char *string);函数名: gettext功能: 将文本方式屏幕上的文本拷贝到存储区用法: int gettext(int left, int top, int right, int bottom, void *destin);函数名: gettextinfo功能: 取得文本模式的显示信息用法: void gettextinfo(struct text_info *inforec);函数名: gettextsettings功能: 返回有关当前图形文本字体的信息用法: void far gettextsettings(struct textsettingstype far *textinfo); 函数名: gettime功能: 取得系统时间用法: void gettime(struct time *timep);函数名: getvect功能: 取得中断向量入口用法: void interrupt(*getvect(int intr_num));函数名: getverify功能: 返回DOS校验标志状态用法: int getverify(void);函数名: getviewsetting功能: 返回有关当前视区的信息用法: void far getviewsettings(struct viewporttype far *viewport); 函数名: getw功能: 从流中取一整数用法: int getw(FILE *strem);函数名: getx功能: 返回当前图形位置的x坐标用法: int far getx(void);函数名: gety功能: 返回当前图形位置的y坐标用法: int far gety(void);函数名: gmtime功能: 把日期和时间转换为格林尼治标准时间(GMT)用法: struct tm *gmtime(long *clock);函数名: gotoxy功能: 在文本窗口中设置光标用法: void gotoxy(int x, int y);函数名: gotoxy功能: 在文本窗口中设置光标用法: void gotoxy(int x, int y);函数名: graphdefaults功能: 将所有图形设置复位为它们的缺省值用法: void far graphdefaults(void);函数名: grapherrormsg功能: 返回一个错误信息串的指针用法: char *far grapherrormsg(int errorcode);函数名: graphresult功能: 返回最后一次不成功的图形操作的错误代码用法: int far graphresult(void);函数名: _graphfreemem功能: 用户可修改的图形存储区释放函数用法: void far _graphfreemem(void far *ptr, unsigned size);函数名: _graphgetmem功能: 用户可修改的图形存储区分配函数用法: void far *far _graphgetmem(unsigned size);函数名: harderr功能: 建立一个硬件错误处理程序用法: void harderr(int (*fptr)());函数名: hardresume功能: 硬件错误处理函数用法: void hardresume(int rescode);函数名: highvideo功能: 选择高亮度文本字符用法: void highvideo(void);函数名: hypot功能: 计算直角三角形的斜边长用法: double hypot(double x, double y);函数名: imagesize功能: 返回保存位图像所需的字节数用法: unsigned far imagesize(int left, int top, int right, int bottom); 函数名: initgraph功能: 初始化图形系统用法: void far initgraph(int far *graphdriver, int far *graphmode函数名: inport功能: 从硬件端口中输入用法: int inp(int protid);函数名: insline功能: 在文本窗口中插入一个空行用法: void insline(void);函数名: installuserdriver功能: 安装设备驱动程序到BGI设备驱动程序表中用法: int far installuserdriver(char far *name, int (*detect)(void));函数名: installuserfont功能: 安装未嵌入BGI系统的字体文件(CHR)用法: int far installuserfont(char far *name);函数名: int86功能: 通用8086软中断接口用法: int int86(int intr_num, union REGS *inregs, union REGS *outregs) 函数名: int86x功能: 通用8086软中断接口用法: int int86x(int intr_num, union REGS *insegs, union REGS *outregs, 函数名: intdos功能: 通用DOS接口用法: int intdos(union REGS *inregs, union REGS *outregs);函数名: intdosx功能: 通用DOS中断接口用法: int intdosx(union REGS *inregs, union REGS *outregs,struct SREGS *segregs);函数名: intr功能: 改变软中断接口用法: void intr(int intr_num, struct REGPACK *preg);函数名: ioctl功能: 控制I/O设备用法: int ioctl(int handle, int cmd[,int *argdx, int argcx]);函数名: isatty功能: 检查设备类型用法: int isatty(int handle);函数名: itoa功能: 把一整数转换为字符串用法: char *itoa(int value, char *string, int radix);函数名: kbhit功能: 检查当前按下的键用法: int kbhit(void);函数名: keep功能: 退出并继续驻留用法: void keep(int status, int size);函数名: kbhit功能: 检查当前按下的键用法: int kbhit(void);函数名: keep功能: 退出并继续驻留用法: void keep(int status, int size);函数名: labs用法: long labs(long n);函数名: ldexp功能: 计算value*2的幂用法: double ldexp(double value, int exp);函数名: ldiv功能: 两个长整型数相除, 返回商和余数用法: ldiv_t ldiv(long lnumer, long ldenom);函数名: lfind功能: 执行线性搜索用法: void *lfind(void *key, void *base, int *nelem, int width,int (*fcmp)());函数名: line功能: 在指定两点间画一直线用法: void far line(int x0, int y0, int x1, int y1);函数名: linerel功能: 从当前位置点(CP)到与CP有一给定相对距离的点画一直线用法: void far linerel(int dx, int dy);函数名: localtime功能: 把日期和时间转变为结构用法: struct tm *localtime(long *clock);函数名: lock功能: 设置文件共享锁用法: int lock(int handle, long offset, long length);函数名: log功能: 对数函数ln(x)用法: double log(double x);函数名: log10功能: 对数函数log用法: double log10(double x);函数名: longjump功能: 执行非局部转移用法: void longjump(jmp_buf env, int val);函数名: lowvideo功能: 选择低亮度字符用法: void lowvideo(void);函数名: lrotl, _lrotl功能: 将无符号长整型数向左循环移位用法: unsigned long lrotl(unsigned long lvalue, int count);unsigned long _lrotl(unsigned long lvalue, int count);函数名: lsearch功能: 线性搜索用法: void *lsearch(const void *key, void *base, size_t *nelem,size_t width, int (*fcmp)(const void *, const void *));函数名: lseek功能: 移动文件读/写指针用法: long lseek(int handle, long offset, int fromwhere);main()主函数每一C 程序都必须有一main() 函数, 可以根据自己的爱好把它放在程序的某个地方。
C语言函数大全-p开头-完整版

C语言函数大全(p开头)函数名: parsfnm功能: 分析文件名用法: char *parsfnm (char *cmdline, struct fcb *fcbptr, int option);程序例:#include#include#include#includeint main(void){char line[80];struct fcb blk;/* get file name */printf("Enter drive and file name (no path - ie. a:file.dat)\n"); gets(line);/* put file name in fcb */if (parsfnm(line, &blk, 1) == NULL)printf("Error in parsfm call\n");elseprintf("Drive #%d Name: %11s\n", blk.fcb_drive, blk.fcb_name); return 0;}函数名: peek功能: 检查存储单元用法: int peek(int segment, unsigned offset);程序例:#include#include#includeint main(void){int value = 0;printf("The current status of your keyboard is:\n");value = peek(0x0040, 0x0017);if (value & 1)printf("Right shift on\n");elseprintf("Right shift off\n");if (value & 2)printf("Left shift on\n");elseprintf("Left shift off\n");if (value & 4)printf("Control key on\n");elseprintf("Control key off\n");if (value & 8)printf("Alt key on\n");elseprintf("Alt key off\n");if (value & 16)printf("Scroll lock on\n");elseprintf("Scroll lock off\n");if (value & 32)printf("Num lock on\n");elseprintf("Num lock off\n");if (value & 64)printf("Caps lock on\n");elseprintf("Caps lock off\n");return 0;}函数名: peekb功能: 检查存储单元用法: char peekb (int segment, unsigned offset);程序例:#include#include#includeint main(void){int value = 0;printf("The current status of your keyboard is:\n"); value = peekb(0x0040, 0x0017);if (value & 1)printf("Right shift on\n");elseprintf("Right shift off\n");if (value & 2)printf("Left shift on\n");elseprintf("Left shift off\n");if (value & 4)printf("Control key on\n");elseprintf("Control key off\n");if (value & 8)printf("Alt key on\n");elseprintf("Alt key off\n");if (value & 16)printf("Scroll lock on\n");elseprintf("Scroll lock off\n");if (value & 32)printf("Num lock on\n");elseprintf("Num lock off\n");if (value & 64)printf("Caps lock on\n");elseprintf("Caps lock off\n");return 0;}函数名: perror功能: 系统错误信息用法: void perror(char *string);程序例:#includeint main(void){FILE *fp;fp = fopen("perror.dat", "r");if (!fp)perror("Unable to open file for reading");return 0;}函数名: pieslice功能: 绘制并填充一个扇形用法: void far pieslice(int x, int stanle, int endangle, int radius);#include#include#include#includeint 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(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode));printf("Press any key to halt:");getch();exit(1); /* 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, endangle, radius);/* clean up */getch();closegraph();return 0;}函数名: poke功能: 存值到一个给定存储单元用法: void poke(int segment, int offset, int value);程序例:#include#includeint main(void){clrscr();cprintf("Make sure the scroll lock key is off and press any key\r\n");poke(0x0000,0x0417,16);cprintf("The scroll lock is now on\r\n");return 0;}函数名: pokeb功能: 存值到一个给定存储单元用法: void pokeb(int segment, int offset, char value);程序例:#include#includeint main(void){clrscr();cprintf("Make sure the scroll lock key is off and press any key\r\n"); getch();pokeb(0x0000,0x0417,16);cprintf("The scroll lock is now on\r\n");return 0;}函数名: poly功能: 根据参数产生一个多项式用法: double poly(double x, int n, double c[]);程序例:#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 %lf\n", result);return 0;}函数名: pow功能: 指数函数(x的y次方)用法: double pow(double x, double y);程序例:#includeint main(void){double x = 2.0, y = 3.0;printf("%lf raised to %lf is %lf\n", x, y, pow(x, y)); return 0;}函数名: pow10功能: 指数函数(10的p次方)用法: double pow10(int p);程序例:#include#includeint main(void){double p = 3.0;printf("Ten raised to %lf is %lf\n", p, pow10(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 buf[7];char *prefix = buf;char tp[20];printf("prefix 6d 6o 8x 10.2e ""10.2f\n");strcpy(prefix,"%");for (i = 0; i < 2; i++){for (j = 0; j < 2; j++)for (k = 0; k < 2; k++)for (l = 0; l < 2; l++){if (i==0) strcat(prefix,"-");if (j==0) strcat(prefix,"+");if (k==0) strcat(prefix,"#");if (l==0) strcat(prefix,"0");printf("%5s |",prefix);strcpy(tp,prefix);strcat(tp,"6d |");printf(tp,I);strcpy(tp,"");strcpy(tp,prefix);strcat(tp,"6o |");printf(tp,I);strcpy(tp,"");strcpy(tp,prefix);strcat(tp,"8x |");printf(tp,I);strcpy(tp,"");strcpy(tp,prefix);strcat(tp,"10.2e |");printf(tp,R);strcpy(tp,prefix);strcat(tp,"10.2f |");printf(tp,R);printf(" \n");strcpy(prefix,"%");}}return 0;}函数名: putc功能: 输出一字符到指定流中用法: int putc(int ch, FILE *stream);程序例:#includeint main(void){char msg[] = "Hello world\n";int i = 0;while (msg[i])putc(msg[i++], stdout);return 0;函数名: putch功能: 输出字符到控制台用法: int putch(int ch);程序例:#include#includeint main(void){char ch = 0;printf("Input a string:");while ((ch != '\r')){ch = getch();putch(ch);}return 0;}函数名: putchar功能: 在stdout上输出字符用法: int putchar(int ch);程序例:#include/* define some box-drawing characters */ #define LEFT_TOP 0xDA#define RIGHT_TOP 0xBF#define HORIZ 0xC4#define VERT 0xB3#define LEFT_BOT 0xC0#define RIGHT_BOT 0xD9int main(void){char i, j;/* draw the top of the box */putchar(LEFT_TOP);for (i=0; i<10; i++)putchar(HORIZ);putchar(RIGHT_TOP);putchar('\n');/* draw the middle */for (i=0; i<4; i++)putchar(VERT);for (j=0; j<10; j++)putchar(' ');putchar(VERT);putchar('\n');}QQ291911320/* draw the bottom */putchar(LEFT_BOT);for (i=0; i<10; i++)putchar(HORIZ);putchar(RIGHT_BOT);putchar('\n');return 0;}函数名: putenv功能: 把字符串加到当前环境中用法: int putenv(char *envvar);程序例:#include#include#include#include#includeint main(void){char *path, *ptr;int i = 0;/* get the current path environment */ptr = getenv("PATH");/* set up new path */path = malloc(strlen(ptr)+15);strcpy(path,"PATH=");strcat(path,ptr);strcat(path,";c:\\temp");/* replace the current path and display current environment */ putenv(path);while (environ[i])printf("%s\n",environ[i++]);return 0;}函数名: putimage功能: 在屏幕上输出一个位图用法: void far putimage(int x, int y, void far *bitmap, int op);程序例:#include#include#include#include#define ARROW_SIZE 10void 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(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode));printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}maxx = getmaxx();x = 0;y = getmaxy() / 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*ARROW_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, 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 */free(arrow);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);linerel(0, 2*ARROW_SIZE);linerel(2*ARROW_SIZE, -1*ARROW_SIZE);}函数名: putpixel功能: 在指定位置画一像素用法: void far putpixel (int x, int y, int pixelcolor);程序例:#include#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 variables */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode));printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}maxx = getmaxx() + 1;maxy = getmaxy() + 1;maxcolor = getmaxcolor() + 1;while (!kbhit()){/* seed the random number generator */seed = random(32767);srand(seed);for (i=0; i{x = random(maxx);y = random(maxy);color = random(maxcolor);putpixel(x, y, color);}delay(DELAY_TIME);srand(seed);for (i=0; i{x = random(maxx);y = random(maxy);color = random(maxcolor);if (color == getpixel(x, y))putpixel(x, y, 0);}}/* clean up */getch();closegraph();return 0;}函数名: puts功能: 送一字符串到流中用法: int puts(char *string);程序例:#includeint main(void){char string[] = "This is an example output string\n";puts(string);return 0;}函数名: puttext功能: 将文本从存储区拷贝到屏幕用法: int puttext(int left, int top, int right, int bottom, void *source);程序例:#includeint main(void){char buffer[512];/* put some text to the console */clrscr();gotoxy(20, 12);cprintf("This 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, 12);puttext(20, 12, 36, 21, buffer);getch();return 0;}函数名: putw功能: 把一字符或字送到流中用法: int putw(int w, FILE *stream);程序例:#include#include#define FNAME "test.$$$"int main(void){FILE *fp;int word;/* place the word in a file */fp = fopen(FNAME, "wb");if (fp == NULL){printf("Error opening file %s\n", FNAME);exit(1);}word = 94;putw(word,fp);if (ferror(fp))printf("Error writing to file\n");elseprintf("Successful write\n");fclose(fp);/* reopen the file */fp = fopen(FNAME, "rb");if (fp == NULL){printf("Error opening file %s\n", FNAME);exit(1);}/* extract the word */word = getw(fp);if (ferror(fp))printf("Error reading file\n");elseprintf("Successful read: word = %d\n", word); /* clean up */fclose(fp);unlink(FNAME);return 0;}。
C语言中常用函数大全

(一)输入输出常用函数1,printf(1)有符号int%[-][+][0][width][.precision][l][h] d-:左对齐+:正数前加‘+’0:右对齐,acwidth<width,左补零.precision:至少输出位数。
若实际的位数>.precision,按实际输出,否者左边补零(2)无符号int%[-][#][0][width][.precision][l][h] u|o|x|X#:”%o %x/X”输出0,0x,0X.precision:同上,TC/BC包含0x/X,VC下不包含(3)实数输出%[-][+][#][0][width][.precision][l][L] f|e|E|g|G#:必须输出小数点.precision:小数位数(四舍五入)(4)字符和字符串的输出%[-][0][width] c %[-][0][width] [.precision] s.precision:S的前precision位2,scanf%[*][width] [l][h]TypeWith:指定输入数据的宽度,遇空格、Tab、\n结束*:抑制符scanf(“%2d%*2d%3d”,&num1,&num2) 输入123456789\n;num1==12,num2==567.注意:(1)指定width时,读取相应width位,但按需赋值Scanf(“%3c%3c”,&ch1,&ch2)输入a bc d efg ch1==a ch2==d(2)%c 输入单字符时“空格、转义字符”均是有效字符(二)ascll字符/字符串/文件函数1;字符非格式化输入函数(1)int getchar(void) 接受字符,以回车结束,回显(2)int getc(FILE*stream) 从stream中接受字符,以回车结束,回显stream=stdin时,(1)==(2)(3)int getche(void) 直接读取字符,回显conio.h(4)int getchar(void) 直接读取字符,不回显conio.h注意:(1,2)对于回车键返回‘\n’(3,4)对于回车键返回‘\r’2;字符/串非格式化输出函数(1)int putchar(int c) 正常返回字符代码值,出错返回EOF(2)int putc(int c,FILE*stream) 正常返回字符代码值,出错返回EOF stream==stdout(1)=(2)(3)int puts(char*stream) 自动回车换行1;字符串的赋值#include< string.h memory.h >Void *memset (void *s, char ch, unsigned n)将以S为首地址的,一片连续的N个字节内存单元赋值为CH.Void *memcpy ( void *d, void*s, unsigned n)将以S为首地址的一片连续的N个字节内存单元的值拷贝到以D为首地址的一片连续的内存单元中。
c语言函数-文档资料

2、参与表达式的运算。这种方式要求函数是有返回值的。 例如: z=2*max(x,y); 是一个赋值表达式,把max的返回值赋予变量z。
3、函数作为另一个函数调用的实际参数出现。 这种情况是把该函数的返回值作为实参进行传送,因
此要求该函数必须是有返回值的。
§7.4 函数的嵌套调用 (P194) C语言的函数定义都是互相平行的、独立的,即在定义
函数时,一个函数内不能包含另一个函数。 C语言不能嵌套定义函数,但可以嵌套调用函数。即在
调用一个函数过程中,又调用另一个函数。
即被调函数可以作为主调函数去调用其它函数。
§7.5 函数的递归调用(P198)
在调用一个函数的过程中又出现直接或间接地调用该 函数本身,称为函数的递归调用。
1、被调函数为库函数 对库函数的调用不需要再作说明, 但必须把该函数的头
文件用include命令包含在源文件前部。
2、用户自定义的函数 一般应该在主调函数中对被调函数的返回值的类型做说明。 对被调函数的说明也有两种格式,
一种为传统格式,其一般格式为: 类型说明符 被调函数名();
另一种为现代格式,其一般形式为: 类型说明符 被调函数名(类型 形参,类型 形参…);
(3)、回传值类型和函数类型矛盾时,则以函数类型为准, 自动进行类型转换。
§7.3 函数的调用(P82) 一、函数调用的一般形式
函数名 (实参表列) 其中,实参以 “,” 分隔,形、实参数数量相等,类型一致。
从主调函数和被调函数之间数据传送的角度看又可分为 无参函数和有参函数两种。
(1)无参函数 函数定义、函数说明及函数调用中均不带参数。 主调函
在递归调用中, 主调函数又是被调函数。执行递归函 数将反复调用其自身。 每调用一次就进入新的一层。
C语言函数大全(p开头).

C语言函数大全(p开头)函数名: parsfnm功能: 分析文件名用法: char *parsfnm (char *cmdline, struct fcb *fcbptr, int option); 程序例:#include#include#include#includeint main(void){char line[80];struct fcb blk;/* get file name */printf("Enter drive and file name (no path - ie. a:file.dat)\n");gets(line);/* put file name in fcb */if (parsfnm(line, &blk, 1) == NULL)printf("Error in parsfm call\n");elseprintf("Drive #%d Name: %11s\n", blk.fcb_drive, blk.fcb_name); return 0;}函数名: peek功能: 检查存储单元用法: int peek(int segment, unsigned offset);程序例:#include#include#includeint main(void){int value = 0;printf("The current status of your keyboard is:\n");value = peek(0x0040, 0x0017);if (value & 1)printf("Right shift on\n");elseprintf("Right shift off\n");printf("Left shift on\n"); elseprintf("Left shift off\n");if (value & 4)printf("Control key on\n"); elseprintf("Control key off\n"); if (value & 8)printf("Alt key on\n"); elseprintf("Alt key off\n");if (value & 16)printf("Scroll lock on\n"); elseprintf("Scroll lock off\n"); if (value & 32)printf("Num lock on\n"); elseprintf("Num lock off\n");printf("Caps lock on\n");elseprintf("Caps lock off\n");return 0;}函数名: peekb功能: 检查存储单元用法: char peekb (int segment, unsigned offset); 程序例:#include#include#includeint main(void){int value = 0;printf("The current status of your keyboard is:\n"); value = peekb(0x0040, 0x0017);if (value & 1)printf("Right shift on\n");printf("Right shift off\n"); if (value & 2)printf("Left shift on\n"); elseprintf("Left shift off\n");if (value & 4)printf("Control key on\n"); elseprintf("Control key off\n"); if (value & 8)printf("Alt key on\n"); elseprintf("Alt key off\n");if (value & 16)printf("Scroll lock on\n"); elseprintf("Scroll lock off\n"); if (value & 32)printf("Num lock on\n");printf("Num lock off\n");if (value & 64)printf("Caps lock on\n");elseprintf("Caps lock off\n");return 0;}函数名: perror功能: 系统错误信息用法: void perror(char *string);程序例:#includeint main(void){FILE *fp;fp = fopen("perror.dat", "r");if (!fp)perror("Unable to open file for reading");return 0;}函数名: pieslice功能: 绘制并填充一个扇形用法: void far pieslice(int x, int stanle, int endangle, int radius); 程序例:#include#include#include#includeint 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(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:");getch();exit(1); /* 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, endangle, radius);/* clean up */getch();closegraph();return 0;}函数名: poke功能: 存值到一个给定存储单元用法: void poke(int segment, int offset, int value);程序例:#include#includeint main(void){clrscr();cprintf("Make sure the scroll lock key is off and press any key\r\n"); getch();poke(0x0000,0x0417,16);cprintf("The scroll lock is now on\r\n");return 0;}函数名: pokeb功能: 存值到一个给定存储单元用法: void pokeb(int segment, int offset, char value);程序例:#include#includeint main(void){clrscr();cprintf("Make sure the scroll lock key is off and press any key\r\n"); getch();pokeb(0x0000,0x0417,16);cprintf("The scroll lock is now on\r\n");return 0;}函数名: poly功能: 根据参数产生一个多项式用法: double poly(double x, int n, double c[]);程序例:#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 %lf\n", result);return 0;}函数名: pow功能: 指数函数(x的y次方)用法: double pow(double x, double y);程序例:#include#includeint main(void){double x = 2.0, y = 3.0;printf("%lf raised to %lf is %lf\n", x, y, pow(x, y));return 0;}函数名: pow10功能: 指数函数(10的p次方)用法: double pow10(int p);程序例:#include#includeint main(void){double p = 3.0;printf("Ten raised to %lf is %lf\n", p, pow10(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 buf[7];char *prefix = buf;char tp[20];printf("prefix 6d 6o 8x 10.2e " "10.2f\n");strcpy(prefix,"%");for (i = 0; i < 2; i++){for (j = 0; j < 2; j++)for (k = 0; k < 2; k++)for (l = 0; l < 2; l++){if (i==0) strcat(prefix,"-");if (j==0) strcat(prefix,"+");if (k==0) strcat(prefix,"#");if (l==0) strcat(prefix,"0"); printf("%5s |",prefix);strcpy(tp,prefix);strcat(tp,"6d |");strcpy(tp,""); strcpy(tp,prefix); strcat(tp,"6o |"); printf(tp,I);strcpy(tp,""); strcpy(tp,prefix); strcat(tp,"8x |"); printf(tp,I);strcpy(tp,""); strcpy(tp,prefix); strcat(tp,"10.2e |"); printf(tp,R); strcpy(tp,prefix); strcat(tp,"10.2f |"); printf(tp,R);printf(" \n"); strcpy(prefix,"%"); }}return 0;}功能: 输出一字符到指定流中用法: int putc(int ch, FILE *stream); 程序例:#includeint main(void){char msg[] = "Hello world\n";int i = 0;while (msg[i])putc(msg[i++], stdout);return 0;}函数名: putch功能: 输出字符到控制台用法: int putch(int ch);程序例:#include#includeint main(void){char ch = 0;printf("Input a string:");while ((ch != '\r')){ch = getch();putch(ch);}return 0;}函数名: putchar功能: 在stdout上输出字符用法: int putchar(int ch);程序例:#include/* define some box-drawing characters */ #define LEFT_TOP 0xDA#define RIGHT_TOP 0xBF#define HORIZ 0xC4#define VERT 0xB3#define LEFT_BOT 0xC0 #define RIGHT_BOT 0xD9 int main(void){char i, j;/* draw the top of the box */ putchar(LEFT_TOP);for (i=0; i<10; i++)putchar(HORIZ);putchar(RIGHT_TOP); putchar('\n');/* draw the middle */for (i=0; i<4; i++){putchar(VERT);for (j=0; j<10; j++)putchar(' ');putchar(VERT);putchar('\n');}/* draw the bottom */putchar(LEFT_BOT);for (i=0; i<10; i++)putchar(HORIZ);putchar(RIGHT_BOT); putchar('\n');return 0;}函数名: putenv功能: 把字符串加到当前环境中用法: int putenv(char *envvar); 程序例:#include#include#include#include#includeint main(void){char *path, *ptr;int i = 0;/* get the current path environment */ptr = getenv("PATH");/* set up new path */path = malloc(strlen(ptr)+15);strcpy(path,"PATH=");strcat(path,ptr);strcat(path,";c:\\temp");/* replace the current path and display current environment */ putenv(path);while (environ[i])printf("%s\n",environ[i++]);return 0;}函数名: putimage功能: 在屏幕上输出一个位图用法: void far putimage(int x, int y, void far *bitmap, int op); 程序例:#include#include#include#include#define ARROW_SIZE 10void 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(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode));printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}maxx = getmaxx();x = 0;y = getmaxy() / 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*ARROW_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, 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 */free(arrow);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); linerel(0, 2*ARROW_SIZE);linerel(2*ARROW_SIZE, -1*ARROW_SIZE);}函数名: putpixel功能: 在指定位置画一像素用法: void far putpixel (int x, int y, int pixelcolor); 程序例:#include#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 variables */ initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}maxx = getmaxx() + 1;maxy = getmaxy() + 1;maxcolor = getmaxcolor() + 1;while (!kbhit()){/* seed the random number generator */seed = random(32767);srand(seed);for (i=0; i{x = random(maxx);y = random(maxy);color = random(maxcolor); putpixel(x, y, color);}delay(DELAY_TIME); srand(seed);for (i=0; i{x = random(maxx);y = random(maxy);color = random(maxcolor); if (color == getpixel(x, y)) putpixel(x, y, 0);}}/* clean up */getch();closegraph();return 0;}函数名: puts功能: 送一字符串到流中用法: int puts(char *string);程序例:#includeint main(void){char string[] = "This is an example output string\n";puts(string);return 0;}函数名: puttext功能: 将文本从存储区拷贝到屏幕用法: int puttext(int left, int top, int right, int bottom, void *source); 程序例:#includeint main(void){char buffer[512];/* put some text to the console */clrscr();gotoxy(20, 12);cprintf("This 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, 12);puttext(20, 12, 36, 21, buffer);getch();return 0;}函数名: putw功能: 把一字符或字送到流中用法: int putw(int w, FILE *stream);程序例:#include#include#define FNAME "test.$$$"int main(void){FILE *fp;int word;/* place the word in a file */fp = fopen(FNAME, "wb");if (fp == NULL){printf("Error opening file %s\n", FNAME); exit(1);}word = 94;putw(word,fp);if (ferror(fp))printf("Error writing to file\n");elseprintf("Successful write\n");fclose(fp);/* reopen the file */fp = fopen(FNAME, "rb");if (fp == NULL){printf("Error opening file %s\n", FNAME); exit(1);}/* extract the word */word = getw(fp);if (ferror(fp))printf("Error reading file\n");elseprintf("Successful read: word = %d\n", word); /* clean up */fclose(fp);unlink(FNAME);return 0;}。
C语言中的22个数学函数

C语言的22个数学函数在使用C语言数学函数时候,应该在该源文件中使用以下命令行:#include <math.h> 或 #include "math.h",这里的<>跟""分别表示:前者表示系统到存放C 库函数头文件所在的目录寻找需要包含的文件,这是标准方式;后者表示系统先在拥护当前目录中寻找要包含的文件,若找不到,再按前者方式查找。
为节省时间,在使用自己编写的文件时使用的是“”,自己编写的文件一般是在当前目录下。
22个数学函数中只有abs的数据类型是:”整型“,”int“。
log10、logE中的10与E是在log的左下角位置。
其余求弧度函数需要看清楚是不是指数。
排列方式如下:函数名:函数功能参数介绍,返回值,说明。
函数原型。
1.abs: 求整型x的绝对值,返回计算结果。
int abs(int x);2.acos:计算COS-1(x)的值,返回计算结果,x应在-1到1范围内。
double acos(double x);3.asin: 计算SIN-1(x)的值,返回计算结果,x应在-1到1范围内。
double asin(double x);4.atan: 计算TAN-1(x)的值,返回计算结果。
double atan(double x);5.atan2: 计算TAN-1/(x/y)的值,返回计算结果。
double atan2(double x,double y);6.cos: 计算COS(x)的值,返回计算结果,x的单位为弧度。
double cos(double x);7.cosh: 计算x的双曲余弦COSH(x)的值,返回计算结果。
double cosh(double x);8.exp: 求e x的值,返回计算结果。
double exp(double x);9.fabs: 求x的绝对值,返回计算结果。
duoble fabs(fouble x);10.floor: 求出不大于x的最大整数,返回该整数的双精度实数。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
函数大全(p开头)61函数名:parsfnm功能:分析文件名用法:char *parsfnm (char *cmdline, struct fcb *fcbptr, int option); 程序例:#include <process.h>#include <string.h>#include <stdio.h>#include <dos.h>int main(void){char line[80];struct fcb blk;/* get file name */printf(M Enter drive and file name (no path - ie. a:file.dat)\n M);gets(line);/* put file name in fcb */if (parsfnm(line, &blk, 1) == NULL)printf(M Error in parsfm call\n H);elseprintf("Drive #%d Name: %1 ls\n", blk.fcb_drive, blk.fcb_name);return 0;函数名:peek功能:检查存储单元用法:int peek(int segment, unsigned offset); 程序例:#include <stdio.h>#include <conio.h>#include <dos.h>int main(void)int value = 0;prinif(=The current sUHus of yourkeyboardis,n=);value HPeek(oxoo4p0x0017)八if(value1)P S-二 f(--Right shift onm=)八elseprintaRight shift05n =)八if(value2)primf(=Lefrshiftonvr.relseprin-fTLenshiftO 51T );if(value&. 4) printf(=con=rolkeyon\n=)_ elsep r i n .s =c o =r o】keyoff\n=)八if(value Rp8)printf(=Alrkey on\n=)一elsep r i n s ->-tkey03=)if (v a c e8l16)prin 〔f(=scro=ock 02n=relseprimf(=scro=ockoff\n=);if (v a c e8c32)primf(=Numlockon\n=);elseprinif(=Numo c k off\n=);if (v a c e8l64)primacaps lockonw);elseprimf(二caps ock03=)因磬Ik 【功能:检查存储单元用法:char peekb (int segment, unsigned offset); 程序例:#include <stdio.h>#include <conio.h>#include <dos.h>int main(void){int value = 0;printf("The current status of your keyboard is:\n"); value = peekb(0x0040, 0x0017);if (value & 1)printf("Right shift on\n");elseprintf(M Right shift off\n M);if (value & 2)printf("Left shift on\n");elseprintf("Left shift off\n H);if (value & 4)printf(''Control key on\n H);elseprintf("Control key off\n");if (value & 8)printf("Alt key on\n");elseprintf("Alt key oflAn");if (value & 16)printf("Scroll lock on\n u);elseprintfC'Scroll lock off\n,f);if (value & 32)printfC'Num lock on\n u);elseprintf("Num lock off\n u);if (value & 64) printfC'Caps lock on\n");elseprintf(H Caps lock off\n");return 0;函数名:perror功能:系统错误信息用法:void perror(char ^string);程序例:#include <stdio.h>int main(void){FILE *fp;fp = fopen("peiTor.dat'\ "r");perror(H Unable to open file for reading0); return 0;函数名:pieslice功能:绘制并填充一个扇形用法:void far pieslice(int x, int stanle, int endangle, int radius); 程序例:#include <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio-h>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(&gdriver,&gmode,HH);/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf(H Graphics error: %s\n H, grapheiTormsg(errorcode));printf(n Press 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, endangle, radius);/* clean up */ getch(); closegraph(); return 0;函数名:poke功能:存值到一个给定存储单元用法:void poke(int segment, int offset, int value);程序例:#include <dos.h>#include <conio.h>int main(void){clrscr();cprintf(n Make sure the scroll lock key is off and press any key\r\n H); getch();poke(0x0000,0x0417,16);cprintf(n The scroll lock is now on\r\n H); return 0;函数名:pokeb功能:存值到一个给定存储单元用法:void pokeb(int segment, int offset, char value);程序例:#include <dos.h>#include <conio-h>int main(void){clrscr();cprintf(H Make sure the scroll lock key is off and press any key\r\n H); getch();pokeb(0x0000,0x0417,16);cprintf(n The scroll lock is now on\r\n M);return 0;函数名:poly功能:根据参数产生一个多项式用法:double poly(double x, int n, double c[J);程序例:#include <stdio.h>#include <math.h>/* 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 %lf\n", result);return 0;函数名:pow功能:指数函数(x的y次方)用法:double pow(double x, double y);程序例:#include <math.h>#include <stdio.h>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 <math.h>#inelude <stdio.h>int main(void){double p = 3.0;printf(M Ten raised to %lf is %lf\n H, p, powlO(p)); return 0;函数名:printf功能:产生格式化输出的函数用法:int printf(char *format…); 程序例:#include <stdio.h>#include <string.h> #define I 555#define R 5.5int main(void){int i,j,k,l;char buf[71;char ^prefix = buf;printf(M prefix 6d 60 8x 10.2e”10.22”);strcpy(prefix,"%n);for (i = 0; i < 2; i++){for(j = 0;j<2;j++)for (k = 0; k < 2; k++)for (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,H O M); 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,"8x 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 \n H); strcpy(prefix/'%");)}return 0;函数名:putc功能:输出一字符到指定流中用法:int putc(int ch, FILE * stream); 程序例:#include <stdio.h>int main(void){char msg[] = M Hello world\n H;int i = 0;putc(msg[i++], stdout);return 0;函数名:putch功能:输出字符到控制台用法:int putch(int ch);程序例:#include <stdio.h>#include <conio.h> int 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 <stdio.h>/* define some box-drawing characters */#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; i<10; i++)putchar(HORIZ);putchar(RIGHT_TOP); putcharC^n');/* draw the middle */for (i=0; i<4; i++){putchar(VERT); for(j=0;j<10;j++)putchar('');putchar(VERT);putchar('\n');/* draw the bottom */ putchar(LEFT_BOT); for (i=0; i<10; i++) putchar(HORIZ);putchar(RIGHT_BOT); putchar('\n‘);return 0;函数名:putenv功能:把字符串加到当前环境中用法:int putenv(char *envvar);程序例:#include <stdio.h>#include <stdlib.h>#include <alloc.h>#include <string.h>#include <dos.h>int main(void){char *path, *ptr;int i = 0;/* get the current path envi「onment */ptr = getenv("PATH M);/* set up new path ♦/path = malloc(strlen(ptr)+15);strcpy(path,M PATH=M);strcat(path,ptr);strcat(path/,;c:\\temp u);/* replace the current path and display current environment */ putenv(path);while (environ[i])printf("%s\n",environfi++]);return 0;函数名:put image功能:在屏幕上输出一个位图用了去:void far putimage(int x, int y, void far ^bitmap, int op); 程序例:#inelude <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>#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(&gdrivei\ &gmode,HU);/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf(n Graphics error: %s\n M, grapheiTormsg(errorcode)); printf(H Press any key to halt:”);getch();exit(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 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 */ 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 y, int pixelcolor); 程序例:#inelude <graphics.h>#include <stdlib.h>#include <stdio.h> #include <conio.h>#include <dos.h> #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(&gdriver, &gmode,HU);/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf(n Graphics error: %s\n'\ grapheiTormsg(errorcode)); printf(H Press any key to halt:11);getch();exit(l); /* terminate with an error code */maxx = getmaxx() + 1;maxy = getmaxy() + 1;maxcolor = getmaxcolor() + 1;while (!kbhit()){/* seed the random number generator */seed = ran dom(32767);srand(seed);for (i=0; i<PIXEL_COUNT; i++){x = random(maxx);y = ran dom(niaxy);color = random(maxcolor); putpixel(x, y, color);}delay(DELAY_TIME); srand(seed);for (i=0; i<PIXEL_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功能:送一字符串到流中用法:int puts(char *string);程序例:#include <stdio.h>int main(void){char string[] = 'This is an example output string\n M;puts(string); return 0;函数名:puttext功能:将文本从存储区拷贝到屏幕用法:int puttext(int left, int top, int right, int bottom, void *source); 程序例:#include <conio.h>int main(void){char buffer[512J;/* put some text to the console */clrscr();gotoxy(20, 12);cprintf(u This 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, 12);puttext(20, 12, 36, 21, buffer);getch();return 0;函数名:putw功能:把一字符或字送到流中用法:int putw(int w, FILE *stream);程序例:#include <stdio.h>#include <stdlib.h>#define FNAME n test.$$$H int main(void) {FILE *fp;int word;/* place the word in a file */ fp = fopen(FNAME, n wb u); if(fp==NULL) printf("Error opening file %s\n", FNAME); exit(l);}word = 94;putw(word,fp);if (ferror(fp))printf("Error writing to file\n");elseprintf("Successful write\n u);fclose(fp);/* reopen the file */fp = fopen(FNAME, M rb M);if (fp == NULL){printfC'Enor opening file %s\n", FNAME); exit(l);1/* extract the word */word = getw(fp);if (ferror(fp))printf("EiTor reading file\n");elseprintf(H Successful read: word = %d\n f\ word);/* clean up */fclose(fp);unlink(FNAME);return 0;。