资源预览内容
第1页 / 共16页
第2页 / 共16页
第3页 / 共16页
第4页 / 共16页
第5页 / 共16页
第6页 / 共16页
第7页 / 共16页
第8页 / 共16页
第9页 / 共16页
第10页 / 共16页
亲,该文档总共16页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
文档供参考,可复制、编制,期待您的好评与关注! C语言函数大全(c开头)函数名: cabs功能: 计算复数的绝对值用法: double cabs(struct complex z);程序例:#include#includeint main(void)struct complex z;double val;z.x = 2.0;z.y = 1.0;val = cabs(z);printf(The absolute value of %.2lfi %.2lfj is %.2lf, z.x, z.y, val);return 0;函数名: calloc功能: 分配主存储器用法: void *calloc(size_t nelem, size_t elsize);程序例:#include#includeint main(void)char *str = NULL;/* allocate memory for string */str = calloc(10, sizeof(char);/* copy Hello into string */strcpy(str, Hello);/* display string */printf(String is %sn, str);/* free memory */free(str);return 0;函数名: ceil功能: 向上舍入用法: double ceil(double x);程序例:#include#includeint main(void)double number = 123.54;double down, up;down = floor(number);up = ceil(number);printf(original number %5.2lfn, number);printf(number rounded down %5.2lfn, down);printf(number rounded up %5.2lfn, up);return 0;函数名: cgets功能: 从控制台读字符串用法: char *cgets(char *str);程序例:#include#includeint main(void)char buffer83;char *p;/* Theres space for 80 characters plus the NULL terminator */buffer0 = 81;printf(Input some chars:);p = cgets(buffer);printf(ncgets read %d characters: %sn, buffer1, p);printf(The returned pointer is %p, buffer0 is at %pn, p, &buffer);/* Leave room for 5 characters plus the NULL terminator */buffer0 = 6;printf(Input some chars:);p = cgets(buffer);printf(ncgets read %d characters: %sn, buffer1, p);printf(The returned pointer is %p, buffer0 is at %pn, p, &buffer);return 0;函数名: chdir功能: 改变工作目录用法: int chdir(const char *path);程序例:#include#include#includechar old_dirMAXDIR;char new_dirMAXDIR;int main(void)if (getcurdir(0, old_dir)perror(getcurdir();exit(1);printf(Current directory is: %sn, old_dir);if (chdir()perror(chdir();exit(1);if (getcurdir(0, new_dir)perror(getcurdir();exit(1);printf(Current directory is now: %sn, new_dir);printf(nChanging back to orignal directory: %sn, old_dir);if (chdir(old_dir)perror(chdir();exit(1);return 0;函数名: _chmod, chmod功能: 改变文件的访问方式用法: int chmod(const char *filename, int permiss);程序例:#include#include#includevoid make_read_only(char *filename);int main(void)make_read_only(NOTEXIST.FIL);make_read_only(MYFILE.FIL);return 0;void make_read_only(char *filename)int stat;stat = chmod(filename, S_IREAD);if (stat)printf(Couldnt make %s read-onlyn, filename);elseprintf(Made %s read-onlyn, filename);函数名: chsize功能: 改变文件大小用法: int chsize(int handle, long size);程序例:#include#include#includeint main(void)int handle;char buf11 = 0123456789;/* create text file containing 10 bytes */handle = open(DUMMY.FIL, O_CREAT);write(handle, buf, strlen(buf);/* truncate the file to 5 bytes in size */chsize(handle, 5);/* close the file */close(handle);return 0;函数名: circle功能: 在给定半径以(x, y)为圆心画圆用法: void far circle(int x, int y, int radius);程序例:#include#include#include#includeint main(void)/* request auto detection */int gdriver = DETECT, gmode, errorcode;int midx, midy;int 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: %sn, grapherrormsg(errorcode);printf(Press any key to halt:);getch();exit(1); /* terminate with an error code */midx = getmaxx() / 2;midy = getmaxy() / 2;setcolor(getmaxcolor();/* draw the circle */circle(midx, midy, radius);/* clean up */getch();closegraph();return 0;函数名: cleardevice功能: 清除图形屏幕用法: void far cleardevice(void);程序例:#include#include#include#includeint main(void)/* request auto detection */int gdriver = DETECT, gmode, errorcode;int midx, midy;/* initialize graphics and local variables */initgraph(&gdriver, &gmode, );/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */printf(Graphics error: %sn, grapherrormsg(errorcode);printf(Press any key to halt:);getch();exit(1); /* terminate with an error code */midx = getmaxx() / 2;midy = getmaxy() / 2;setcolor(getmaxcolor();/* for centering screen messages */settextjustify(CENTER_TEXT, CENTER_TEXT);/* output a message to the screen */outtextxy(midx, midy, press any key to clear the screen:);/* wait for a key */getch();/* clear the screen */cleardevice();/* output another message */outtextxy(midx, midy, press any key to quit:);/* clean up */getch();closegraph();return 0;函数名: clearerr功能: 复位错误标志用法:void clearerr(FILE *stream);程序例:#includeint main(void
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号