C语言函数(c开头)
c开头的编程语言

编程语言C语言(C Programming Language)是一种广泛使用的高级编程语言,由美国计算机科学家Dennis M. Ritchie于1972年发明。
C语言具有简洁、高效、可移植性强、可扩展性强等优点,被广泛应用于系统软件、应用软件、嵌入式系统等领域。
C语言的基本语法包括变量、数据类型、控制结构、函数等,支持指针、结构体等复杂数据类型,支持低级内存操作,可以与汇编语言混合编程。
C语言还提供了标准库和第三方库,方便开发人员快速开发应用程序。
C语言是一种非常强大的编程语言,不仅可以用于编写操作系统、编译器等底层软件,还可以用于编写各种应用软件、游戏等上层软件。
同时,C语言也是一种比较难学的编程语言,需要开发人员具有较强的算法和数据结构基础。
C语言常用库函数

输出的字符ch,若出错,返回EOF
Putchar
Int putchar (char ch)
把字符ch输出到标准输出设备
输出的字符ch,若出错,返回EOF
Puts
Int puts(char *str)
把str指向的字符串输出到标准输出设备,将’\0’转换为回车换行
返回换行符,若失败,返回EOF
关闭fp所指的文件,释放文件缓存区
有错则返回非0;否则返回0
Feof
Int feof(FILE *fp)
检查文件是否结束
遇文件结束符返回非0值;否则返回0
Fgetc
Int fgetc(FILE *fp)
从fp所指定的文件中取得下一个字符
返回所得到的字符,若读入错误,返回EOF
Fgets
Char *fgets(char *buf,int n,FILE *fp)
Putw
Int putw(int w,FILE *fp)
将一个整数w(即一个字)写到fp指向的文件中
返回输出的整数,若出错,返回EOF
非ANSI标准
Read
Int read(int fd,char *buf,unsigned count)
从文件号fd所指示的文件中读count个字节到由buf指示的缓冲区中
Args为指针
Write
计算sin-1(x)的值
计算结果
X应在-1到1范围内
atan
double atan(double x)
计算tan-1(x)的值
计算结果
Atan2
double atan2(double x,double y)
计算tan-1(x/y)的值
c语言函数命名规范

竭诚为您提供优质文档/双击可除c语言函数命名规范篇一:c语言命名规则匈牙利命名法是微软推广的一种关于变量、函数、对象、前缀、宏定义等各种类型的符号的命名规范。
匈牙利命名法的主要思想是:在变量和函数名中加入前缀以增进人们对程序的理解。
它是由微软内部的一个匈牙利人发起使用的,结果它在微软内部逐渐流行起来,并且推广给了全世界的windows开发人员。
下面将介绍匈牙利命名法,后面的例子里也会尽量遵守它和上面的代码风格。
aarray数组bbool(int)布尔(整数)byunsignedchar(byte)无符号字符(字节)cchar字符(字节)cbcountofbytes字节数crcolorreferencevalue颜色(参考)值cxcountofx(short)x的集合(短整数)dwdwoRd(unsignedlong)双字(无符号长整数)fFlags(usuallymultiplebitvalues)标志(一般是有多位的数值)fnFunction函数g_global全局的hhandle句柄iintegerllonglplongpointerm_datamemberofaclass成员nshortintppointersstringszzeroterminatedstring符串tmtextmetricuunsignedintulunsignedlong(ulong)整数长整数长指针一个类的数据短整数指针字符串以0结尾的字文本规则无符号整数无符号长整数wwoRd(unsignedshort)无符号短整数x,yx,ycoordinates(short)坐标值/短整数vvoid空有关项目的全局变量用g_开始,类成员变量用m_,局部变量若函数较大则可考虑用l_用以显示说明其是局部变量。
前缀类型例子g_全局变量g_serversc类或者结构体cdocument,cprintinfom_成员变量m_pdoc,m_ncustomersVc常用前缀列表:前缀类型描述例子chchar8位字符chgradechtchaR16位unicode类型字符chnamebbool布尔变量benablednint整型(其大小由操作系统决定)nlengthnuint无符号整型(其大小由操作系统决定)nlength wwoRd16位无符号整型wposllong32位有符号整型loffsetdwdwoRd32位无符号整型dwRangep*ambientmemorymodelpointer内存模块指针,指针变量pdoclpFaR*长指针lpdoclpszlpstR32位字符串指针lpsznamelpszlpcstR32位常量字符串指针lpsznamelpszlpctstR32位unicode类型常量指针lpszname hhandlewindows对象句柄hwndlpfn(*fn)()回调函数指针callbackFarpointertocallbackfunctionlpfnabort windows对象名称缩写:windows对象例子变量mFc类例子对象hwndhwnd;cwnd*pwnd;hdlghdlg;cdialog*pdlg;hdchdc;cdc*pdc;hgdiobjhgdiobj;cgdiobject*pgdiobj;hpenhpen;cpen*ppen;hbRushhbrush;cbrush*pbrush;hFonthFont;cFont*pFont;hbitmaphbitmap;cbitmap*pbitmap;hpalettehpalette;cpalette*ppalette;hRgnhRgn;cRgn*pRgn;hmenuhmenu;cmenu*pmenu;hwndhctl;cstatic*pstatic;hwndhctl;cbutton*pbtn;hwndhctl;cedit*pedit;hwndhctl;clistbox*plistbox;hwndhctl;ccombobox*pcombobox;Vc常用宏定义命名列表:前缀符号类型符号例子范围篇二:c语言变量命名规则1、严格采用阶梯层次组织程序代码:各层次缩进的分格采用Vc的缺省风格,即每层次缩进为4格,括号位于下一行。
c语言 文件操作函数

c语言文件操作函数C语言文件操作函数C语言文件操作函数是C语言提供的一种文件操作方式,可以通过这些函数来读取、写入和修改文件。
文件操作函数可以帮助我们完成很多与文件有关的任务,比如读取配置文件、保存用户数据等。
在本文中,将介绍C语言中常用的文件操作函数。
打开文件在C语言中,我们可以使用fopen()函数来打开一个文件。
该函数的原型如下:FILE *fopen(const char *filename, const char *mode);其中,filename表示要打开的文件名,mode表示打开文件的模式。
mode的取值如下:- "r":以只读方式打开文件- "w":以写方式打开文件,如果文件不存在,则创建该文件;如果文件已存在,则清空该文件- "a":以写方式打开文件,如果文件不存在,则创建该文件;如果文件已存在,则在文件末尾追加数据- "r+":以读写方式打开文件,文件必须存在- "w+":以读写方式打开文件,如果文件不存在,则创建该文件;如果文件已存在,则清空该文件- "a+":以读写方式打开文件,如果文件不存在,则创建该文件;如果文件已存在,则在文件末尾追加数据例如,我们可以使用以下代码来打开一个名为example.txt的文件:FILE *fp;fp = fopen("example.txt", "w+");if (fp == NULL) {printf("Open file failed!\n");}在打开文件之后,我们可以使用fclose()函数来关闭文件,释放文件资源。
例如:fclose(fp);读取文件在C语言中,我们可以使用fscanf()函数从文件中读取数据。
该函数的原型如下:int fscanf(FILE *stream, const char *format, ...);其中,stream表示要读取数据的文件,format表示数据的格式。
c语言开头格式

C语言的开头格式通常包括头文件和main函数,具体如下:
1. 头文件:#include <stdio.h>
这是一个预处理指令,它指示编译器在编译过程中引入标准输入输出库(stdio.h),以便后续的程序可以使用标准输入输出函数,例如printf()和scanf()等。
2. main函数:int main()
这是C语言程序的入口函数,程序将从这里开始执行。
main函数必须返回一个整数值,通常情况下,返回值为0表示程序正常结束,非0值则表示程序异常结束。
在main函数中可以编写程序代码,完成特定的任务。
例如,可以编写代码来计算两个数的和、输出一段文本、读取用户输入等等。
c语言常用的函数

C语言常用的特定函数1. printf 函数1.1 定义printf是C语言中最常用的输出函数,用于将格式化的数据打印到标准输出设备(通常是显示器)。
1.2 用途printf函数用于在程序运行时向屏幕上输出信息,可以输出各种类型的数据,包括字符串、整数、浮点数等。
它可以根据指定的格式将数据转换为字符串并输出。
1.3 工作方式printf函数使用格式化字符串作为参数,格式化字符串中包含了要输出的内容以及一些控制输出格式的特殊字符。
当程序执行到printf函数时,它会按照格式化字符串的要求将相应的数据转换为字符串并输出到标准输出设备。
以下是一些常用的格式化字符:•%d:用于输出十进制整数。
•%f:用于输出浮点数。
•%s:用于输出字符串。
•%c:用于输出字符。
下面是一个示例代码:#include <stdio.h>int main() {int num = 10;float pi = 3.14159;char str[] = "Hello, World!";printf("整数:%d\n", num);printf("浮点数:%f\n", pi);printf("字符串:%s\n", str);return 0;}运行结果:整数:10浮点数:3.141590字符串:Hello, World!2. scanf 函数2.1 定义scanf是C语言中常用的输入函数,用于从标准输入设备(通常是键盘)读取格式化的数据。
2.2 用途scanf函数用于从用户输入中获取数据,可以读取各种类型的数据,包括整数、浮点数、字符等。
2.3 工作方式scanf函数使用格式化字符串作为参数,格式化字符串中包含了要读取的数据类型以及一些控制读取格式的特殊字符。
当程序执行到scanf函数时,它会根据格式化字符串的要求从标准输入设备中读取相应的数据,并将其存储到指定的变量中。
c语言函数命名规范

竭诚为您提供优质文档/双击可除c语言函数命名规范篇一:c语言命名规则匈牙利命名法是微软推广的一种关于变量、函数、对象、前缀、宏定义等各种类型的符号的命名规范。
匈牙利命名法的主要思想是:在变量和函数名中加入前缀以增进人们对程序的理解。
它是由微软内部的一个匈牙利人发起使用的,结果它在微软内部逐渐流行起来,并且推广给了全世界的windows开发人员。
下面将介绍匈牙利命名法,后面的例子里也会尽量遵守它和上面的代码风格。
aarray数组bbool(int)布尔(整数)byunsignedchar(byte)无符号字符(字节)cchar字符(字节)cbcountofbytes字节数crcolorreferencevalue颜色(参考)值cxcountofx(short)x的集合(短整数)dwdwoRd(unsignedlong)双字(无符号长整数)fFlags(usuallymultiplebitvalues)标志(一般是有多位的数值)fnFunction函数g_global全局的hhandle句柄iintegerllonglplongpointerm_datamemberofaclass成员nshortintppointersstringszzeroterminatedstring符串tmtextmetricuunsignedintulunsignedlong(ulong)整数长整数长指针一个类的数据短整数指针字符串以0结尾的字文本规则无符号整数无符号长整数wwoRd(unsignedshort)无符号短整数x,yx,ycoordinates(short)坐标值/短整数vvoid空有关项目的全局变量用g_开始,类成员变量用m_,局部变量若函数较大则可考虑用l_用以显示说明其是局部变量。
前缀类型例子g_全局变量g_serversc类或者结构体cdocument,cprintinfom_成员变量m_pdoc,m_ncustomersVc常用前缀列表:前缀类型描述例子chchar8位字符chgradechtchaR16位unicode类型字符chnamebbool布尔变量benablednint整型(其大小由操作系统决定)nlengthnuint无符号整型(其大小由操作系统决定)nlength wwoRd16位无符号整型wposllong32位有符号整型loffsetdwdwoRd32位无符号整型dwRangep*ambientmemorymodelpointer内存模块指针,指针变量pdoclpFaR*长指针lpdoclpszlpstR32位字符串指针lpsznamelpszlpcstR32位常量字符串指针lpsznamelpszlpctstR32位unicode类型常量指针lpszname hhandlewindows对象句柄hwndlpfn(*fn)()回调函数指针callbackFarpointertocallbackfunctionlpfnabort windows对象名称缩写:windows对象例子变量mFc类例子对象hwndhwnd;cwnd*pwnd;hdlghdlg;cdialog*pdlg;hdchdc;cdc*pdc;hgdiobjhgdiobj;cgdiobject*pgdiobj;hpenhpen;cpen*ppen;hbRushhbrush;cbrush*pbrush;hFonthFont;cFont*pFont;hbitmaphbitmap;cbitmap*pbitmap;hpalettehpalette;cpalette*ppalette;hRgnhRgn;cRgn*pRgn;hmenuhmenu;cmenu*pmenu;hwndhctl;cstatic*pstatic;hwndhctl;cbutton*pbtn;hwndhctl;cedit*pedit;hwndhctl;clistbox*plistbox;hwndhctl;ccombobox*pcombobox;Vc常用宏定义命名列表:前缀符号类型符号例子范围篇二:c语言变量命名规则1、严格采用阶梯层次组织程序代码:各层次缩进的分格采用Vc的缺省风格,即每层次缩进为4格,括号位于下一行。
c语言中函数名和变量名的命名规则

c语言中函数名和变量名的命名规则
C语言作为一种广泛应用的计算机编程语言,在程序设计中有着重要的地位。
其中函数和变量是程序中的两个重要概念,而函数名和变量名
的命名规则又是程序设计中的基础。
函数名的命名规则
1. 函数名的命名应该具有代表性,能够清晰地表达函数的功能与作用。
2. 函数名应该全部由小写字母组成,单词之间用下划线分隔。
3. 函数名应该以单词动词开头,例如print_message()。
4. 函数名应该避免使用系统保留字,如system, exit等。
5. 函数名长度原则上不应超过30个字符,充分表达即可。
变量名的命名规则
1. 变量名的命名同样应该具有代表性,能够清晰地表达变量的意义。
2. 变量名应该全部由小写字母组成,单词之间用下划线分隔。
3. 变量名可以以字母或下划线开头,但是不允许以数字开头。
4. 变量名应该遵循驼峰命名法,即首字母小写而后面的每个单词的首
字母都大写,例如studentName。
5. 变量名长度原则上不应超过30个字符,充分表达即可。
总结
在C语言中,函数名和变量名的命名规则对于程序设计至关重要,一个良好的命名可以提高程序的可读性和可维护性。
因此在进行函数名和变量名的命名时,我们应该时刻遵循以上规则,养成良好的编程风格,最终得到一个高质量的、易于运行和修改的程序。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
函数大全(c开头) 61函数名: 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 %s\n", 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.2lf\n", number); printf("number rounded down %5.2lf\n", down); printf("number rounded up %5.2lf\n", up);return 0;}函数名: cgets功能: 从控制台读字符串用法: char *cgets(char *str);程序例:#include#includeint main(void){char buffer[83];char *p;/* There's space for 80 characters plus the NULL terminator */ buffer[0] = 81;printf("Input some chars:");p = cgets(buffer);printf("\ncgets read %d characters: \"%s\"\n", buffer[1], p);printf("The returned pointer is %p, buffer[0] is at %p\n", p, &buffer);/* Leave room for 5 characters plus the NULL terminator */buffer[0] = 6;printf("Input some chars:");p = cgets(buffer);printf("\ncgets read %d characters: \"%s\"\n", buffer[1], p);printf("The returned pointer is %p, buffer[0] is at %p\n", p, &buffer); return 0;}函数名: chdir功能: 改变工作目录用法: int chdir(const char *path);程序例:#include#include#includechar old_dir[MAXDIR];char new_dir[MAXDIR];int main(void){if (getcurdir(0, old_dir)){perror("getcurdir()");exit(1);}printf("Current directory is: \\%s\n", old_dir);if (chdir("\\")){perror("chdir()");exit(1);}if (getcurdir(0, new_dir)){perror("getcurdir()");exit(1);}printf("Current directory is now: \\%s\n", new_dir);printf("\nChanging back to orignal directory: \\%s\n", 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("Couldn't make %s read-only\n", filename); elseprintf("Made %s read-only\n", filename);}函数名: chsize功能: 改变文件大小用法: int chsize(int handle, long size);程序例:#include#include#includeint main(void){int handle;char buf[11] = "0123456789";/* create text file containing 10 bytes */handle = open("DUMMY.FIL", O_CREA T); 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: %s\n", 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: %s\n", 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){FILE *fp;char ch;/* open a file for writing */fp = fopen("DUMMY.FIL", "w");/* force an error condition by attempting to read */ ch = fgetc(fp);printf("%c\n",ch);if (ferror(fp)){/* display an error message */printf("Error reading from DUMMY.FIL\n");/* reset the error and EOF indicators */clearerr(fp);}fclose(fp);return 0;}函数名: clearviewport功能: 清除图形视区用法: void far clearviewport(void);程序例:#include#include#include#include#define CLIP_ON 1 /* activates clipping in viewport */int main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int ht;/* 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 */}setcolor(getmaxcolor());ht = textheight("W");/* message in default full-screen viewport */outtextxy(0, 0, "* <-- (0, 0) in default viewport");/* create a smaller viewport */setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON);/* display some messages */outtextxy(0, 0, "* <-- (0, 0) in smaller viewport"); outtextxy(0, 2*ht, "Press any key to clear viewport:");/* wait for a key */getch();/* clear the viewport */clearviewport();/* output another message */outtextxy(0, 0, "Press any key to quit:");/* clean up */getch();closegraph();return 0;}函数名: _close, close功能: 关闭文件句柄用法: int close(int handle);程序例:#include#include#include#includemain(){int handle;char buf[11] = "0123456789";/* create a file containing 10 bytes */handle = open("NEW.FIL", O_CREAT);if (handle > -1){write(handle, buf, strlen(buf));/* close the file */close(handle);}else{printf("Error opening file\n");}return 0;}函数名: clock功能: 确定处理器时间用法: clock_t clock(void);程序例:#include#include#includeint main(void){clock_t start, end;start = clock();delay(2000);end = clock();printf("The time was: %f\n", (end - start) / CLK_TCK);return 0;}函数名: closegraph功能: 关闭图形系统用法: void far closegraph(void);#include#include#include#includeint main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int x, y;/* initialize graphics mode */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an erroroccurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}x = getmaxx() / 2;y = getmaxy() / 2;/* output a message */settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(x, y, "Press a key to close the graphics system:");/* wait for a key */getch();/* closes down the graphics system */closegraph();printf("We're now back in text mode.\n");printf("Press any key to halt:");getch();}函数名: clreol功能: 在文本窗口中清除字符到行末用法: void clreol(void);程序例:#includeint main(void){clrscr();cprintf("The function CLREOL clears all characters from the\r\n"); cprintf("cursor position to the end of the line within the\r\n"); cprintf("current text window, without moving the cursor.\r\n"); cprintf("Press any key to continue . . .");gotoxy(14, 4);getch();clreol();getch();return 0;}函数名: clrscr功能: 清除文本模式窗口用法: void clrscr(void);程序例:#includeint main(void){int i;for (i = 0; i < 20; i++)cprintf("%d\r\n", i);cprintf("\r\nPress any key to clear screen");getch();clrscr();cprintf("The screen has been cleared!");getch();return 0;}函数名: coreleft功能: 返回未使用内存的大小用法: unsigned coreleft(void);程序例:#include#includeint main(void){printf("The difference between the highest allocated block and\n"); printf("the top of the heap is: %lu bytes\n", (unsigned long) coreleft());return 0;}函数名: cos功能: 余弦函数用法: double cos(double x);程序例:#include#includeint main(void){double result;double x = 0.5;result = cos(x);printf("The cosine of %lf is %lf\n", x, result);return 0;}函数名: cosh功能: 双曲余弦函数用法: dluble cosh(double x);程序例:#include#includeint main(void){double result;double x = 0.5;result = cosh(x);printf("The hyperboic cosine of %lf is %lf\n", x, result);return 0;}函数名: country功能: 返回与国家有关的信息用法: struct COUNTRY *country(int countrycode, struct country *country); 程序例:#include#include#define USA 0int main(void){struct COUNTRY country_info;country(USA, &country_info);printf("The currency symbol for the USA is: %s\n", country_info.co_curr);return 0;}函数名: cprintf功能: 送格式化输出至屏幕用法: int cprintf(const char *format[, argument, ...]); 程序例:#includeint main(void){/* clear the screen */clrscr();/* create a text window */window(10, 10, 80, 25);/* output some text in the window */cprintf("Hello world\r\n");/* wait for a key */getch();return 0;}函数名: cputs功能: 写字符到屏幕用法: void cputs(const char *string);程序例:#includeint main(void)/* clear the screen */clrscr();/* create a text window */window(10, 10, 80, 25);/* output some text in the window */cputs("This is within the window\r\n");/* wait for a key */getch();return 0;}函数名: _creat creat功能: 创建一个新文件或重写一个已存在的文件用法: int creat (const char *filename, int permiss);程序例:#include#include#include#includeint main(void){int handle;char buf[11] = "0123456789";/* change the default file mode from text to binary */_fmode = O_BINARY;/* create a binary file for reading and writing */handle = creat("DUMMY.FIL", S_IREAD | S_IWRITE);/* write 10 bytes to the file */write(handle, buf, strlen(buf));/* close the file */close(handle);}函数名: creatnew功能: 创建一个新文件用法: int creatnew(const char *filename, int attrib); 程序例:#include#include#include#include#includeint main(void){int handle;char buf[11] = "0123456789";/* attempt to create a file that doesn't already exist */ handle = creatnew("DUMMY.FIL", 0);if (handle == -1)printf("DUMMY.FIL already exists.\n");else{printf("DUMMY.FIL successfully created.\n");write(handle, buf, strlen(buf));close(handle);}return 0;}函数名: creattemp功能: 创建一个新文件或重写一个已存在的文件用法: int creattemp(const char *filename, int attrib); 程序例:#include#includeint main(void){int handle;char pathname[128];strcpy(pathname, "\\");/* create a unique file in the root directory */handle = creattemp(pathname, 0);printf("%s was the unique file created.\n", pathname); close(handle);return 0;}函数名: cscanf功能: 从控制台执行格式化输入用法: int cscanf(char *format[,argument, ...]);程序例:#includeint main(void){char string[80];/* clear the screen */clrscr();/* Prompt the user for input */cprintf("Enter a string with no spaces:");/* read the input */cscanf("%s", string);/* display what was read */cprintf("\r\nThe string entered is: %s", string); return 0;}函数名: ctime功能: 把日期和时间转换为字符串用法: char *ctime(const time_t *time);程序例:#include#includeint main(void){time_t t;time(&t);printf("Today's date and time: %s\n", ctime(&t)); return 0;}函数名: ctrlbrk功能: 设置Ctrl-Break处理程序用法: void ctrlbrk(*fptr)(void);程序例:#include#include#define ABORT 0int c_break(void){printf("Control-Break pressed. Program aborting ...\n"); return (ABORT);}int main(void){ctrlbrk(c_break);for(;;){printf("Looping... Press to quit:\n");}return 0;}函数大全(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 %s\n", 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.2lf\n", number); printf("number rounded down %5.2lf\n", down); printf("number rounded up %5.2lf\n", up);return 0;}函数名: cgets功能: 从控制台读字符串用法: char *cgets(char *str);程序例:#include#includeint main(void){char buffer[83];char *p;/* There's space for 80 characters plus the NULL terminator */ buffer[0] = 81;printf("Input some chars:");p = cgets(buffer);printf("\ncgets read %d characters: \"%s\"\n", buffer[1], p);printf("The returned pointer is %p, buffer[0] is at %p\n", p, &buffer);/* Leave room for 5 characters plus the NULL terminator */buffer[0] = 6;printf("Input some chars:");p = cgets(buffer);printf("\ncgets read %d characters: \"%s\"\n", buffer[1], p);printf("The returned pointer is %p, buffer[0] is at %p\n", p, &buffer); return 0;}函数名: chdir功能: 改变工作目录用法: int chdir(const char *path);程序例:#include#include#includechar old_dir[MAXDIR];char new_dir[MAXDIR];int main(void){if (getcurdir(0, old_dir)){perror("getcurdir()");exit(1);}printf("Current directory is: \\%s\n", old_dir);if (chdir("\\")){perror("chdir()");exit(1);}if (getcurdir(0, new_dir)){perror("getcurdir()");exit(1);}printf("Current directory is now: \\%s\n", new_dir);printf("\nChanging back to orignal directory: \\%s\n", 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("Couldn't make %s read-only\n", filename); elseprintf("Made %s read-only\n", filename);}函数名: chsize功能: 改变文件大小用法: int chsize(int handle, long size);程序例:#include#include#includeint main(void){int handle;char buf[11] = "0123456789";/* create text file containing 10 bytes */handle = open("DUMMY.FIL", O_CREA T); 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: %s\n", 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: %s\n", 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){FILE *fp;char ch;/* open a file for writing */fp = fopen("DUMMY.FIL", "w");/* force an error condition by attempting to read */ch = fgetc(fp);printf("%c\n",ch);if (ferror(fp)){/* display an error message */printf("Error reading from DUMMY.FIL\n");/* reset the error and EOF indicators */clearerr(fp);}fclose(fp);return 0;}函数名: clearviewport功能: 清除图形视区用法: void far clearviewport(void);程序例:#include#include#include#include#define CLIP_ON 1 /* activates clipping in viewport */int main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int ht;/* 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 */}setcolor(getmaxcolor());ht = textheight("W");/* message in default full-screen viewport */outtextxy(0, 0, "* <-- (0, 0) in default viewport");/* create a smaller viewport */setviewport(50, 50, getmaxx()-50, getmaxy()-50, CLIP_ON);/* display some messages */outtextxy(0, 0, "* <-- (0, 0) in smaller viewport"); outtextxy(0, 2*ht, "Press any key to clear viewport:");/* wait for a key */getch();/* clear the viewport */clearviewport();/* output another message */outtextxy(0, 0, "Press any key to quit:");/* clean up */getch();closegraph();return 0;}函数名: _close, close功能: 关闭文件句柄用法: int close(int handle);程序例:#include#include#include#includemain(){int handle;char buf[11] = "0123456789";/* create a file containing 10 bytes */handle = open("NEW.FIL", O_CREAT);if (handle > -1){write(handle, buf, strlen(buf));/* close the file */close(handle);}else{printf("Error opening file\n");}return 0;}函数名: clock功能: 确定处理器时间用法: clock_t clock(void);程序例:#include#include#includeint main(void){clock_t start, end;start = clock();delay(2000);end = clock();printf("The time was: %f\n", (end - start) / CLK_TCK); return 0;}函数名: closegraph功能: 关闭图形系统用法: void far closegraph(void);程序例:#include#include#include#includeint main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int x, y;/* initialize graphics mode */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an erroroccurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}x = getmaxx() / 2;y = getmaxy() / 2;/* output a message */settextjustify(CENTER_TEXT, CENTER_TEXT); outtextxy(x, y, "Press a key to close the graphics system:");/* wait for a key *//* closes down the graphics system */closegraph();printf("We're now back in text mode.\n");printf("Press any key to halt:");getch();return 0;}函数名: clreol功能: 在文本窗口中清除字符到行末用法: void clreol(void);程序例:#includeint main(void){clrscr();cprintf("The function CLREOL clears all characters from the\r\n"); cprintf("cursor position to the end of the line within the\r\n"); cprintf("current text window, without moving the cursor.\r\n"); cprintf("Press any key to continue . . .");gotoxy(14, 4);getch();clreol();getch();return 0;}函数名: clrscr功能: 清除文本模式窗口用法: void clrscr(void);#includeint main(void){int i;clrscr();for (i = 0; i < 20; i++)cprintf("%d\r\n", i);cprintf("\r\nPress any key to clear screen");getch();clrscr();cprintf("The screen has been cleared!");getch();return 0;}函数名: coreleft功能: 返回未使用内存的大小用法: unsigned coreleft(void);程序例:#include#includeint main(void){printf("The difference between the highest allocated block and\n"); printf("the top of the heap is: %lu bytes\n", (unsigned long) coreleft());return 0;}函数名: cos功能: 余弦函数用法: double cos(double x);#include#includeint main(void){double result;double x = 0.5;result = cos(x);printf("The cosine of %lf is %lf\n", x, result);return 0;}函数名: cosh功能: 双曲余弦函数用法: dluble cosh(double x);程序例:#include#includeint main(void){double result;double x = 0.5;result = cosh(x);printf("The hyperboic cosine of %lf is %lf\n", x, result);return 0;}函数名: country功能: 返回与国家有关的信息用法: struct COUNTRY *country(int countrycode, struct country *country); 程序例:#include#define USA 0int main(void){struct COUNTRY country_info;country(USA, &country_info);printf("The currency symbol for the USA is: %s\n", country_info.co_curr);return 0;}函数名: cprintf功能: 送格式化输出至屏幕用法: int cprintf(const char *format[, argument, ...]); 程序例:#includeint main(void){/* clear the screen */clrscr();/* create a text window */window(10, 10, 80, 25);/* output some text in the window */cprintf("Hello world\r\n");/* wait for a key */getch();return 0;}函数名: cputs功能: 写字符到屏幕用法: void cputs(const char *string);程序例:#includeint main(void){/* clear the screen */clrscr();/* create a text window */window(10, 10, 80, 25);/* output some text in the window */cputs("This is within the window\r\n");/* wait for a key */getch();return 0;}函数名: _creat creat功能: 创建一个新文件或重写一个已存在的文件用法: int creat (const char *filename, int permiss); 程序例:#include#include#include#includeint main(void){int handle;char buf[11] = "0123456789";/* change the default file mode from text to binary */ _fmode = O_BINARY;/* create a binary file for reading and writing */handle = creat("DUMMY.FIL", S_IREAD | S_IWRITE);/* write 10 bytes to the file */write(handle, buf, strlen(buf));/* close the file */close(handle);return 0;}函数名: creatnew功能: 创建一个新文件用法: int creatnew(const char *filename, int attrib);程序例:#include#include#include#include#includeint main(void){int handle;char buf[11] = "0123456789";/* attempt to create a file that doesn't already exist */ handle = creatnew("DUMMY.FIL", 0);if (handle == -1)printf("DUMMY.FIL already exists.\n");else{printf("DUMMY.FIL successfully created.\n");write(handle, buf, strlen(buf));close(handle);}return 0;}函数名: creattemp功能: 创建一个新文件或重写一个已存在的文件用法: int creattemp(const char *filename, int attrib); 程序例:#include#include#includeint main(void){int handle;char pathname[128];strcpy(pathname, "\\");/* create a unique file in the root directory */handle = creattemp(pathname, 0);printf("%s was the unique file created.\n", pathname); close(handle);return 0;}函数名: cscanf功能: 从控制台执行格式化输入用法: int cscanf(char *format[,argument, ...]);程序例:#includeint main(void){char string[80];/* clear the screen */clrscr();/* Prompt the user for input */cprintf("Enter a string with no spaces:");。