C语言函数大全(C)
C语言字符串处理函数大全
不错不错.
long strtol( const char *nptr, char **endptr, int base );
long wcstol( const wchar_t *nptr, wchar_t **endptr, int base );
unsigned long strtoul( const char *nptr, char **endptr, int base );
void *memchr( const void *buf, int c, size_t count );
在内存中寻找字符c并返回其地址,如果没有找到,返回NULL
C语言中的字符串操作
char *strcat( char *strDestination, const char *strSource );
int strcmp( const char *string1, const char *string2 );
int wcscmp( const wchar_t *string1, const wchar_t *string2 );
int _mbscmp(const unsigned char *string1, const unsigned char *string2 );
在一个字符串里查找一个字串,返回不包含目标串的长度。注意,好像MSDN上说是第一个strCharSet中任意原子的地方。不知道这样的话还有什么意义。
size_t strftime( char *strDest, size_t maxsize, const char *format, const struct tm *timeptr );
size_t wcsftime( wchar_t *strDest, size_t maxsize, const wchar_t *format, const struct tm *timeptr );
(完整word版)C语言函数用法大全
函数名: stpcpy功能: 拷贝一个字符串到另一个用法: char *stpcpy(char *destin, char *source); 程序例:#include <stdio.h>#include <string.h>int main(void){char string[10];char *str1 = "abcdefghi";stpcpy(string, str1);printf("%s\n", string);return 0;}函数名: strcat功能: 字符串拼接函数用法: char *strcat(char *destin, char *source); 程序例:#include <string.h>#include <stdio.h>int main(void){char destination[25];char *blank = " ", *c = "C++", *Borland = "Borland";strcpy(destination, Borland);strcat(destination, blank);strcat(destination, c);printf("%s\n", destination);return 0;}函数名: strchr功能: 在一个串中查找给定字符的第一个匹配之处\用法: char *strchr(char *str, char c);程序例:#include <string.h>#include <stdio.h>{char string[15];char *ptr, c = 'r';strcpy(string, "This is a string");ptr = strchr(string, c);if (ptr)printf("The character %c is at position: %d\n", c, ptr-string);elseprintf("The character was not found\n");return 0;}函数名: strcmp功能: 串比较用法: int strcmp(char *str1, char *str2);看Asic码,str1>str2,返回值> 0;两串相等,返回0程序例:#include <string.h>#include <stdio.h>{char *buf1 = "aaa", *buf2 = "bbb", *buf3 = "ccc";int ptr;ptr = strcmp(buf2, buf1);if (ptr > 0)printf("buffer 2 is greater than buffer 1\n");elseprintf("buffer 2 is less than buffer 1\n");ptr = strcmp(buf2, buf3);if (ptr > 0)printf("buffer 2 is greater than buffer 3\n");elseprintf("buffer 2 is less than buffer 3\n");return 0;}函数名: strncmpi功能: 将一个串中的一部分与另一个串比较, 不管大小写用法: int strncmpi(char *str1, char *str2, unsigned maxlen); 程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "BBB", *buf2 = "bbb";int ptr;ptr = strcmpi(buf2, buf1);if (ptr > 0)printf("buffer 2 is greater than buffer 1\n");if (ptr < 0)printf("buffer 2 is less than buffer 1\n");if (ptr == 0)printf("buffer 2 equals buffer 1\n");return 0;}函数名: strcpy功能: 串拷贝用法: char *strcpy(char *str1, char *str2); 程序例:#include <stdio.h>#include <string.h>int main(void){char string[10];char *str1 = "abcdefghi";strcpy(string, str1);printf("%s\n", string);return 0;}函数名: strcspn功能: 在串中查找第一个给定字符集内容的段用法: int strcspn(char *str1, char *str2); 程序例:#include <stdio.h>#include <string.h>#include <alloc.h>int main(void){char *string1 = "1234567890";char *string2 = "747DC8";int length;length = strcspn(string1, string2);printf("Character where strings intersect is at position %d\n", length);return 0;}函数名: strdup功能: 将串拷贝到新建的位置处用法: char *strdup(char *str);程序例:#include <stdio.h>#include <string.h>#include <alloc.h>int main(void){char *dup_str, *string = "abcde";dup_str = strdup(string);printf("%s\n", dup_str);free(dup_str);return 0;}函数名: stricmp功能: 以大小写不敏感方式比较两个串用法: int stricmp(char *str1, char *str2);程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "BBB", *buf2 = "bbb";int ptr;ptr = stricmp(buf2, buf1);if (ptr > 0)printf("buffer 2 is greater than buffer 1\n");if (ptr < 0)printf("buffer 2 is less than buffer 1\n");if (ptr == 0)printf("buffer 2 equals buffer 1\n");return 0;}函数名: strerror功能: 返回指向错误信息字符串的指针用法: char *strerror(int errnum);程序例:#include <stdio.h>#include <errno.h>int main(void){char *buffer;buffer = strerror(errno);printf("Error: %s\n", buffer);return 0;}函数名: strcmpi功能: 将一个串与另一个比较, 不管大小写用法: int strcmpi(char *str1, char *str2);程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "BBB", *buf2 = "bbb";int ptr;ptr = strcmpi(buf2, buf1);if (ptr > 0)printf("buffer 2 is greater than buffer 1\n");if (ptr < 0)printf("buffer 2 is less than buffer 1\n");if (ptr == 0)printf("buffer 2 equals buffer 1\n");return 0;}函数名: strncmp功能: 串比较用法: int strncmp(char *str1, char *str2, int maxlen);程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "aaabbb", *buf2 = "bbbccc", *buf3 = "ccc";int ptr;ptr = strncmp(buf2,buf1,3);if (ptr > 0)printf("buffer 2 is greater than buffer 1\n");elseprintf("buffer 2 is less than buffer 1\n");ptr = strncmp(buf2,buf3,3);if (ptr > 0)printf("buffer 2 is greater than buffer 3\n");elseprintf("buffer 2 is less than buffer 3\n");return(0);}函数名: strncmpi功能: 把串中的一部分与另一串中的一部分比较, 不管大小写用法: int strncmpi(char *str1, char *str2);程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "BBBccc", *buf2 = "bbbccc";int ptr;ptr = strncmpi(buf2,buf1,3);if (ptr > 0)printf("buffer 2 is greater than buffer 1\n");if (ptr < 0)printf("buffer 2 is less than buffer 1\n");if (ptr == 0)printf("buffer 2 equals buffer 1\n");return 0;}函数名: strncpy功能: 串拷贝用法: char *strncpy(char *destin, char *source, int maxlen); 程序例:#include <stdio.h>#include <string.h>int main(void){char string[10];char *str1 = "abcdefghi";strncpy(string, str1, 3);string[3] = '\0';printf("%s\n", string);return 0;}函数名: strnicmp功能: 不注重大小写地比较两个串用法: int strnicmp(char *str1, char *str2, unsigned maxlen); 程序例:#include <string.h>#include <stdio.h>int main(void){char *buf1 = "BBBccc", *buf2 = "bbbccc";int ptr;ptr = strnicmp(buf2, buf1, 3);if (ptr > 0)printf("buffer 2 is greater than buffer 1\n");if (ptr < 0)printf("buffer 2 is less than buffer 1\n");if (ptr == 0)printf("buffer 2 equals buffer 1\n");return 0;}函数名: strnset功能: 将一个串中的所有字符都设为指定字符用法: char *strnset(char *str, char ch, unsigned n); 程序例:#include <stdio.h>#include <string.h>int main(void){char *string = "abcdefghijklmnopqrstuvwxyz";char letter = 'x';printf("string before strnset: %s\n", string);strnset(string, letter, 13);printf("string after strnset: %s\n", string);return 0;}函数名: strpbrk功能: 在串中查找给定字符集中的字符用法: char *strpbrk(char *str1, char *str2);程序例:#include <stdio.h>#include <string.h>int main(void){char *string1 = "abcdefghijklmnopqrstuvwxyz";char *string2 = "onm";char *ptr;ptr = strpbrk(string1, string2);if (ptr)printf("strpbrk found first character: %c\n", *ptr);elseprintf("strpbrk didn't find character in set\n");return 0;}函数名: strrchr功能: 在串中查找指定字符的最后一个出现用法: char *strrchr(char *str, char c);程序例:#include <string.h>#include <stdio.h>int main(void){char string[15];char *ptr, c = 'r';strcpy(string, "This is a string");ptr = strrchr(string, c);if (ptr)printf("The character %c is at position: %d\n", c, ptr-string);elseprintf("The character was not found\n");return 0;}函数名: strrev功能: 串倒转用法: char *strrev(char *str);程序例:#include <string.h>#include <stdio.h>int main(void){char *forward = "string";printf("Before strrev(): %s\n", forward);strrev(forward);printf("After strrev(): %s\n", forward);return 0;}函数名: strset功能: 将一个串中的所有字符都设为指定字符用法: char *strset(char *str, char c);程序例:#include <stdio.h>#include <string.h>int main(void){char string[10] = "123456789";char symbol = 'c';printf("Before strset(): %s\n", string);strset(string, symbol);printf("After strset(): %s\n", string);return 0;}函数名: strspn功能: 在串中查找指定字符集的子集的第一次出现用法: int strspn(char *str1, char *str2);程序例:#include <stdio.h>#include <string.h>#include <alloc.h>int main(void){char *string1 = "1234567890";char *string2 = "123DC8";int length;length = strspn(string1, string2);printf("Character where strings differ is at position %d\n", length);return 0;}函数名: strstr功能: 在串中查找指定字符串的第一次出现用法: char *strstr(char *str1, char *str2);程序例:#include <stdio.h>#include <string.h>int main(void){char *str1 = "Borland International", *str2 = "nation", *ptr;ptr = strstr(str1, str2);printf("The substring is: %s\n", ptr);return 0;}函数名: strtod功能: 将字符串转换为double型值用法: double strtod(char *str, char **endptr);程序例:#include <stdio.h>#include <stdlib.h>int main(void){char input[80], *endptr;double value;printf("Enter a floating point number:");gets(input);value = strtod(input, &endptr);printf("The string is %s the number is %lf\n", input, value);return 0;}函数名: strtok功能: 查找由在第二个串中指定的分界符分隔开的单词用法: char *strtok(char *str1, char *str2);程序例:#include <string.h>#include <stdio.h>int main(void){char input[16] = "abc,d";char *p;/* strtok places a NULL terminatorin front of the token, if found */p = strtok(input, ",");if (p) printf("%s\n", p);/* A second call to strtok using a NULLas the first parameter returns a pointerto the character following the token */p = strtok(NULL, ",");if (p) printf("%s\n", p);return 0;}函数名: strtol功能: 将串转换为长整数用法: long strtol(char *str, char **endptr, int base); 程序例:#include <stdlib.h>#include <stdio.h>int main(void){char *string = "87654321", *endptr;long lnumber;/* strtol converts string to long integer */lnumber = strtol(string, &endptr, 10);printf("string = %s long = %ld\n", string, lnumber);return 0;}函数名: strupr功能: 将串中的小写字母转换为大写字母用法: char *strupr(char *str);程序例:#include <stdio.h>#include <string.h>int main(void){char *string = "abcdefghijklmnopqrstuvwxyz", *ptr;/* converts string to upper case characters */ptr = strupr(string);printf("%s\n", ptr);return 0;}函数名: swab功能: 交换字节用法: void swab (char *from, char *to, int nbytes); 程序例:#include <stdlib.h>#include <stdio.h>#include <string.h>char source[15] = "rFna koBlrna d";char target[15];int main(void){swab(source, target, strlen(source));printf("This is target: %s\n", target);return 0;}。
C语言函数库详解(收藏版)
c语言函数库目录第一章(C标准库) ............................................................... 错误!未定义书签。
1. <>:诊断............................................................................. 错误!未定义书签。
2. <>:字符类别测试 ............................................................ 错误!未定义书签。
3. <>:错误处理..................................................................... 错误!未定义书签。
4. <>:整型常量..................................................................... 错误!未定义书签。
5. <>:地域环境..................................................................... 错误!未定义书签。
6. <>:数学函数..................................................................... 错误!未定义书签。
7. <>:非局部跳转................................................................. 错误!未定义书签。
8. <>:信号............................................................................. 错误!未定义书签。
c语言常用函数大全
c语言常用函数大全1.int iscntrl(int c) 判断字符c是否为控制字符。
2.int isalnum(int c) 判断字符c是否为字母或数字3.int isalpha(int c) 判断字符c是否为英文字母4.int isascii(int c) 判断字符c是否为ascii码5.int isblank(int c) 判断字符c是否为TAB或空格6.int isdigit(int c) 判断字符c是否为数字7.int isgraph(int c) 判断字符c是否为除空格外的可打印字符8.int islower(int c) 判断字符c是否为小写英文字母9.int isprint(int c) 判断字符c是否为可打印字符(含空格)10.int ispunct(int c) 判断字符c是否为标点符号11.int isspace(int c) 判断字符c是否为空白符12.int isupper(int c) 判断字符c是否为大写英文字母13.int isxdigit(int c) 判断字符c是否为十六进制数字14.int toascii(int c) 将字符c转换为ascii码15.int tolower(int c) 将字符c转换为小写英文字母16.int toupper(int c); 将字符c转换为大写英文字母17.float fabs(float x) 求浮点数x的绝对值18.int abs(int x) 求整数x的绝对值19.float acos(float x) 求x(弧度表示)的反余弦值20.float asin(float x) 求x(弧度表示)的反正弦值21.float atan(float x) 求x(弧度表示)的反正切值22.float atan2(float y, float x) 求y/x(弧度表示)的反正切值23.float ceil(float x) 求不小于x的最小整数24.float cos(float x) 求x(弧度表示)的余弦值25.float cosh(float x) 求x的双曲余弦值26.float exp(float x) 求e的x次幂。
C语言库函数大全
C语言库函数大全absread()读磁盘绝对扇区函数原形:int absread(int drive,int num,int sectnum,void *buf)功能:从drive指定的驱动器磁盘上,sectnum指定的逻辑扇区号开始读取(通过DOS中断0x25读取)num个(最多64K个)扇区的内容,储存于buf所指的缓冲区中。
参数:drive=0对应A盘,drive=1对应B盘。
返回值:0:成功;-1:失败。
头文件:dos.habswrite()写磁盘绝对扇区函数原形:int abswrite(int drive,int nsects,int lsect,void *buffer)drive=0(A驱动器)、1(B驱动器)、nsects=要写的扇区数(最多64K个);lsect=起始逻辑扇区号;buffer=要写入数据的内存起始地址。
功能:将指定内容写入(调用DOS中断0x26)磁盘上的指定扇区,即使写入的地方是磁盘的逻辑结构、文件、FAT表和目录结构所在的扇区,也照常进行。
返回值:0:成功;-1:失败。
头文件:dos.hatof()将字符串转换成浮点数的函数原形:double atof(const char *s)功能:把s所指向的字符串转换成double类型。
s格式为:符号数字.数字 E符号数字返回值:字符串的转换值。
头文件:math.h、stdlib.hatoi()将字符串转换成整型数的函数原形:int atoi(const char *s)功能:把s所指向的字符串转换成int类型。
s格式为:符号数字返回值:字符串的转换值。
若出错则返回0。
头文件:stdlib.hatol()将字符串转换成长整型数的函数原形:long atol(const char *s)功能:把s所指向的字符串转换成long int类型。
s格式为:符号数字返回值:字符串的转换值。
若出错则返回0。
头文件:stdlib.hbcd()把一个数转换成对应的BCD码的函数原形:bcd bcd(int x)bcd bcd(double x)bcd bcd(double x,int decimals)注意:BCD码的精度可达17位。
C语言函数大全-c开头-完整版
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 %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_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: %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());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();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);QQ291911320程序例:#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();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#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:");/* 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语言函数大全
功能: 异常终止一个进程用法: 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语言库函数使用大全
C语言库函数使用大全C语言是一种广泛应用于软件开发领域的编程语言,它提供了许多库函数来方便开发者编写高效且可靠的程序。
本文将为大家介绍一些常用的C语言库函数,以及它们的使用方法和示例代码。
一、stdio.h 库函数1. printf 函数:用于在控制台输出指定格式的数据。
示例代码:```c#include <stdio.h>int main() {int number = 10;printf("The number is %d\n", number);return 0;}```2. scanf 函数:用于从控制台读取输入数据。
示例代码:```c#include <stdio.h>int main() {int number;printf("Please enter a number: ");scanf("%d", &number);printf("You entered: %d\n", number);return 0;}```二、stdlib.h 库函数1. malloc 函数:用于在堆中分配指定大小的内存空间。
示例代码:```c#include <stdlib.h>int main() {int *numbers = (int*) malloc(5 * sizeof(int));for (int i = 0; i < 5; i++) {numbers[i] = i + 1;}for (int i = 0; i < 5; i++) {printf("%d ", numbers[i]);}free(numbers);return 0;}```2. rand 函数:用于生成随机数。
示例代码:```c#include <stdio.h>#include <stdlib.h>#include <time.h>int main() {srand(time(NULL));int randomNumber = rand() % 100;printf("Random number: %d\n", randomNumber);return 0;}```三、string.h 库函数1. strcpy 函数:用于将一个字符串复制到另一个字符串。
C语言中常用函数大全
(三)文件函数
mode: r:打开已存在文件,准备从文件中读取数据 ,不能写入 r+ :可读可写
w:创建一个新文件,准备写入;如文件已存在,此文件将被 空文件覆盖 w+:增加“读取”操作
2;字符ar(int c) 正常返回字 符代码值,出错返回 E OF (2)int putc(int c,FILE*strea m) 正常返回字 符代码值,出错返回 E OF strea m==stdou t(1)=(2) (3)int puts(char*strea m) 自动回车换 行
a:打开已存在文件,准备在文件尾部追加数 据,不能读取。 如文件不存在,侧创建此文 件,准备写入。
a+:增加“读取”
t:打开一个文 本文件(缺省值) b:打开一个二 进制文件
一:文件的打开 与关闭 1:打开文件 FILE * fopen (char*filen ame, char*mode) Filename:是字符串,表示打开的文件名,文件名前可 以带路径。 Mode:也是字符串,表示打开文 件的方式。 功能----按指定方式 打开文件。 返回值----如果文件打开成功,返回“文件结构体 指针”,否者返回 N ULL(如:文件不存在 或则 写文件时不能创建 )。 Fopen(“A:\\user\\asd.txt”,”r+”); 2:关闭文件 Int*fclos e(FILE*filen ame) 正常关闭返 回0;否者返回 非 0。
With:指定输入数 据的宽度,遇空格、Tab、\n 结束
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语言函数大全C语言函数大全
AAA.函数名: abort功能: 异常终止一个进程用法: void abort(void);程序例:#include <stdio.h>#include <stdlib.h>int main(void){printf("Calling abort()\n");abort();return 0; /* This is never reached */}函数名: abs功能: 求整数的绝对值用法: int abs(int i);程序例:#include <stdio.h>#include <math.h>int main(void){int number = -1234;printf("number: %d absolute value: %d\n", number, abs(number)); return 0;}函数名: absread, abswirte功能: 绝对磁盘扇区读、写数据用法: int absread(int drive, int nsects, int sectno, void *buffer); int abswrite(int drive, int nsects, in tsectno, void *buffer);程序例:/* absread example */#include <stdio.h>#include <conio.h>#include <process.h>#include <dos.h>int main(void){int i, strt, ch_out, sector;char buf[512];printf("Insert a diskette into drive A and press any key\n"); getch();sector = 0;if (absread(0, 1, sector, &buf) != 0){perror("Disk problem");exit(1);}printf("Read OK\n");strt = 3;for (i=0; i<80; i++){ch_out = buf[strt+i];putchar(ch_out);}printf("\n");return(0);}函数名: access功能: 确定文件的访问权限用法: int access(const char *, int amode);程序例:#include <stdio.h>#include <io.h>int (char *);int main(void){printf("Does NOTEXIST.FIL exist: %s\n",("NOTEXISTS.FIL") ? "YES" : "NO");return 0;}int (char *){return (access(, 0) == 0);}函数名: acos功能: 反余弦函数用法: double acos(double x);程序例:#include <stdio.h>#include <math.h>int main(void){double result;double x = 0.5;result = acos(x);printf("The arc cosine of %lf is %lf\n", x, result);return 0;}函数名: allocmem功能: 分配DOS存储段用法: int allocmem(unsigned size, unsigned *seg);程序例:#include <dos.h>#include <alloc.h>#include <stdio.h>int main(void){unsigned int size, segp;int stat;size = 64; /* (64 x 16) = 1024 bytes */stat = allocmem(size, &segp);if (stat == -1)printf("Allocated memory at segment: %x\n", segp);elseprintf("Failed: maximum number of paragraphs available is %u\n",stat);return 0;}函数名: arc功能: 画一弧线用法: void far arc(int x, int y, int stangle, 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;int radius = 100;/* initialize graphics and local variables */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult(); /* an error occurred */if (errorcode != grOk){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 arc */arc(midx, midy, stangle, endangle, radius);/* clean up */getch();closegraph();return 0;}函数名: asctime功能: 转换日期和时间为ASCII码用法: char *asctime(const struct tm *tblock);程序例:#include <stdio.h>#include <string.h>#include <time.h>int main(void){struct tm t;char str[80];/* sample loading of tm structure */t.tm_sec = 1; /* Seconds */t.tm_min = 30; /* Minutes */t.tm_hour = 9; /* Hour */t.tm_mday = 22; /* Day of the Month */t.tm_mon = 11; /* Month */t.tm_year = 56; /* Year - does not include century */t.tm_wday = 4; /* Day of the week */t.tm_yday = 0; /* Does not show in asctime */t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime *//* converts structure to null terminatedstring */strcpy(str, asctime(&t));printf("%s\n", str);return 0;}函数名: asin功能: 反正弦函数用法: double asin(double x);程序例:#include <stdio.h>#include <math.h>int main(void){double result;double x = 0.5;result = asin(x);printf("The arc sin of %lf is %lf\n", x, result);return(0);}函数名: assert功能: 测试一个条件并可能使程序终止用法: void assert(int test);程序例:#include <assert.h>#include <stdio.h>#include <stdlib.h>struct ITEM {int key;int value;};/* add item to list, make sure list is not null */ void additem(struct ITEM *itemptr) {assert(itemptr != NULL);/* add item to list */}int main(void){additem(NULL);return 0;}函数名: atan功能: 反正切函数用法: double atan(double x);程序例:#include <stdio.h>#include <math.h>int main(void){double result;double x = 0.5;result = atan(x);printf("The arc tangent of %lf is %lf\n", x, result);return(0);}函数名: atan2功能: 计算Y/X的反正切值用法: double atan2(double y, double x);程序例:#include <stdio.h>#include <math.h>int main(void){double result;double x = 90.0, y = 45.0;result = atan2(y, x);printf("The arc tangent ratio of %lf is %lf\n", (y / x), result);return 0;}函数名: atexit功能: 注册终止函数用法: int atexit(atexit_t func);程序例:#include <stdio.h>#include <stdlib.h>void exit_fn1(void){printf("Exit function #1 called\n");}void exit_fn2(void){printf("Exit function #2 called\n");}int main(void){/* post exit function #1 */atexit(exit_fn1);/* post exit function #2 */atexit(exit_fn2);return 0;}函数名: atof功能: 把字符串转换成浮点数用法: double atof(const char *nptr);程序例:#include <stdlib.h>#include <stdio.h>int main(void){float f;char *str = "12345.67";f = atof(str);printf("string = %s float = %f\n", str, f);return 0;}函数名: atoi功能: 把字符串转换成长整型数用法: int atoi(const char *nptr);程序例:#include <stdlib.h>#include <stdio.h>int main(void){int n;char *str = "12345.67";n = atoi(str);printf("string = %s integer = %d\n", str, n);return 0;}函数名: atol功能: 把字符串转换成长整型数用法: long atol(const char *nptr);程序例:#include <stdlib.h>#include <stdio.h>int main(void){long l;char *str = "98765432";l = atol(lstr);printf("string = %s integer = %ld\n", str, l);return(0);}BBB.函数名: bar功能: 画一个二维条形图用法: void far bar(int left, int top, int right, int bottom);程序例:#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, i;/* 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;/* loop through the fill patterns */for (i=SOLID_FILL; i<USER_FILL; i++){/* set the fill style */setfillstyle(i, getmaxcolor());/* draw the bar */bar(midx-50, midy-50, midx+50,midy+50);getch();}/* clean up */closegraph();return 0;}函数名: bar3d功能: 画一个三维条形图用法: void far bar3d(int left, int top, int right, int bottom,int depth, int topflag); 程序例:#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, i;/* initialize graphics, 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 error code */}midx = getmaxx() / 2;midy = getmaxy() / 2;/* loop through the fill patterns */for (i=EMPTY_FILL; i<USER_FILL; i++){/* set the fill style */setfillstyle(i, getmaxcolor());/* draw the 3-d bar */bar3d(midx-50, midy-50, midx+50, midy+50, 10, 1);getch();}/* clean up */closegraph();return 0;}函数名: bdos功能: DOS系统调用用法: int bdos(int dosfun, unsigned dosdx, unsigned dosal); 程序例:#include <stdio.h>#include <dos.h>/* Get current drive as 'A', 'B', ... */char current_drive(void){char curdrive;/* Get current disk as 0, 1, ... */curdrive = bdos(0x19, 0, 0);return('A' + curdrive);}int main(void){printf("The current drive is %c:\n", current_drive());return 0;}函数名: bdosptr功能: DOS系统调用用法: int bdosptr(int dosfun, void *argument, unsigned dosal); 程序例:#include <string.h>#include <stdio.h>#include <dir.h>#include <dos.h>#include <errno.h>#include <stdlib.h>#define BUFLEN 80int main(void){char buffer[BUFLEN];int test;printf("Enter full pathname of a directory\n");gets(buffer);test = bdosptr(0x3B,buffer,0);if(test){printf("DOS error message: %d\n", errno);/* See errno.h for error listings */exit (1);}getcwd(buffer, BUFLEN);printf("The current directory is: %s\n", buffer);return 0;}函数名: bioscom功能: 串行I/O通信用法: int bioscom(int cmd, char abyte, int port);程序例:#include <bios.h>#include <conio.h>#define COM1 0#define DATA_READY 0x100#define TRUE 1#define FALSE 0#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)int main(void){int in, out, status, DONE = FALSE;bioscom(0, SETTINGS, COM1);cprintf("... BIOSCOM [ESC] to exit ...\n");while (!DONE){status = bioscom(3, 0, COM1);if (status & DATA_READY)if ((out = bioscom(2, 0, COM1) & 0x7F) != 0)putch(out);if (kbhit()){if ((in = getch()) == '\x1B')DONE = TRUE;bioscom(1, in, COM1);}}return 0;}函数名: biosdisk功能: 软硬盘I/O用法: int biosdisk(int cmd, int drive, int head, int track, int sector int nsects, void *buffer);程序例:#include <bios.h>#include <stdio.h>int main(void){int result;char buffer[512];printf("Testing to see if drive a: is ready\n");result = biosdisk(4,0,0,0,0,1,buffer);result &= 0x02;(result) ? (printf("Drive A: Ready\n")) :(printf("Drive A: Not Ready\n"));return 0;}函数名: biosequip功能: 检查设备用法: int biosequip(void);程序例:#include <bios.h>#include <stdio.h>int main(void){int result;char buffer[512];printf("Testing to see if drive a: is ready\n");result = biosdisk(4,0,0,0,0,1,buffer);result &= 0x02;(result) ? (printf("Drive A: Ready\n")) :(printf("Drive A: Not Ready\n"));return 0;}函数名: bioskey功能: 直接使用BIOS服务的键盘接口用法: int bioskey(int cmd);程序例:#include <stdio.h>#include <bios.h>#include <ctype.h>#define RIGHT 0x01#define LEFT 0x02#define CTRL 0x04#define ALT 0x08int main(void){int key, modifiers;/* function 1 returns 0 until a key is pressed */while (bioskey(1) == 0);/* function 0 returns the key that is waiting */key = bioskey(0);/* use function 2 to determine if shift keys were used */ modifiers = bioskey(2);if (modifiers){printf("[");if (modifiers & RIGHT) printf("RIGHT");if (modifiers & LEFT) printf("LEFT");if (modifiers & CTRL) printf("CTRL");if (modifiers & ALT) printf("ALT");printf("]");}/* print out the character read */if (isalnum(key & 0xFF))printf("'%c'\n", key);elseprintf("%#02x\n", key);return 0;函数名: biosmemory功能: 返回存储块大小用法:int biosmemory(void);程序例:#include <stdio.h>#include <bios.h>int main(void){int memory_size;memory_size = biosmemory(); /* returns value up to 640K */printf("RAM size = %dK\n",memory_size);return 0;}函数名: biosprint功能: 直接使用BIOS服务的打印机I/O用法: int biosprint(int cmd, int byte, int port);程序例:#include <stdio.h>#include <conio.h>#include <bios.h>int main(void){#define STATUS 2 /* printer status command */#define PORTNUM 0 /* port number for LPT1 */int status, abyte=0;printf("Please turn off your printer. Press any key to continue\n");getch();status = biosprint(STATUS, abyte, PORTNUM);if (status & 0x01)printf("Device time out.\n");if (status & 0x08)printf("I/O error.\n");if (status & 0x10)printf("Selected.\n");if (status & 0x20)printf("Out of paper.\n");if (status & 0x40)printf("Acknowledge.\n");if (status & 0x80)printf("Not busy.\n");return 0;}函数名: biostime功能: 读取或设置BIOS时间用法: long biostime(int cmd, long newtime);程序例:#include <stdio.h>#include <bios.h>#include <time.h>#include <conio.h>int main(void){long bios_time;clrscr();cprintf("The number of clock ticks since midnight is:\r\n");cprintf("The number of seconds since midnight is:\r\n");cprintf("The number of minutes since midnight is:\r\n");cprintf("The number of hours since midnight is:\r\n");cprintf("\r\nPress any key to quit:");while(!kbhit()){bios_time = biostime(0, 0L);gotoxy(50, 1);cprintf("%lu", bios_time);gotoxy(50, 2);cprintf("%.4f", bios_time / CLK_TCK);gotoxy(50, 3);cprintf("%.4f", bios_time / CLK_TCK / 60);gotoxy(50, 4);cprintf("%.4f", bios_time / CLK_TCK / 3600);}return 0;}函数名: brk功能: 改变数据段空间分配用法: int brk(void *endds);程序例:#include <stdio.h>#include <alloc.h>int main(void){char *ptr;printf("Changing allocation with brk()\n");ptr = malloc(1);printf("Before brk() call: %lu bytes free\n", coreleft());brk(ptr+1000);printf(" After brk() call: %lu bytes free\n", coreleft());return 0;}函数名: bsearch功能: 二分法搜索用法: void *bsearch(const void *key, const void *base, size_t *nelem, size_t width, int(*fcmp)(const void *, const *));程序例:#include <stdlib.h>#include <stdio.h>#define NELEMS(arr) (sizeof(arr) / sizeof(arr[0]))int numarray[] = {123, 145, 512, 627, 800, 933};int numeric (const int *p1, const int *p2){return(*p1 - *p2);}int lookup(int key){int *itemptr;/* The cast of (int(*)(const void *,const void*))is needed to avoid a type mismatch error atcompile time */itemptr = bsearch (&key, numarray, NELEMS(numarray),sizeof(int), (int(*)(const void *,const void *))numeric);return (itemptr != NULL);}int main(void){if (lookup(512))printf("512 is in the table.\n");elseprintf("512 isn't in the table.\n");return 0;}CCC.函数名: cabs功能: 计算复数的绝对值用法: double cabs(struct complex z);程序例:#include <stdio.h>#include <math.h>int 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 <stdio.h>#include <alloc.h>int 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 <math.h>#include <stdio.h>int 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 <stdio.h>#include <conio.h>int 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 <stdio.h>#include <stdlib.h>#include <dir.h>char 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 *, int permiss);程序例:#include <sys\stat.h>#include <stdio.h>#include <io.h>void make_read_only(char *);int main(void){make_read_only("NOTEXIST.FIL");make_read_only("MY");return 0;}void make_read_only(char *){int stat;stat = chmod(, S_IREAD);if (stat)printf("Couldn't make %s read-only\n", );elseprintf("Made %s read-only\n", );}函数名: chsize功能: 改变文件大小用法: int chsize(int handle, long size);程序例:#include <string.h>#include <fcntl.h>#include <io.h>int main(void){int handle;char buf[11] = "0123456789";/* create text 10 bytes */handle = open("DUMMY.FIL", O_CREAT);write(handle, buf, strlen(buf));/* truncate the 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 <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 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 <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;/* 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);程序例:#include <stdio.h>int main(void){FILE *fp;char ch;/* open a 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 <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>#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 <string.h>#include <stdio.h>#include <fcntl.h>#include <io.h>main(){int handle;char buf[11] = "0123456789";/* create a 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 <time.h>#include <stdio.h>#include <dos.h>int 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 <graphics.h>#include <stdlib.h>#include <stdio.h>#include <conio.h>int 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();return 0;}函数名: clreol功能: 在文本窗口中清除字符到行末用法: void clreol(void);程序例:#include <conio.h>int 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);程序例:#include <conio.h>int 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 <stdio.h>#include <alloc.h>int 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 <stdio.h>#include <math.h>int 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 <stdio.h>#include <math.h>int 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); 程序例:。
C语言函数大全(精简版)
字符串函数∙bcmp∙bcopy∙bzero∙memccpy ∙memchr ∙memcmp ∙memcpy ∙memicmp ∙memmove ∙memset ∙movmem ∙setmem ∙stpcpy ∙strcat ∙strchr ∙strcmp ∙strcmpi ∙strcpy ∙strcspn ∙strdup ∙stricmp ∙strlen ∙strlwr ∙strncat ∙strncmp ∙strncmpi ∙strncpy ∙strnicmp ∙strpbrk ∙strrev ∙strset ∙strstr ∙strtok ∙strupr数学函数∙abs∙acos∙asin∙atan∙atan2∙ceil∙cos∙cosh∙exp∙fabs∙floor∙fmod∙frexp∙hypot∙ldexp∙log∙log10∙modf∙pow∙pow10∙sin∙sinh∙sqrt∙tan∙tanh输入输出函数∙getchar∙kbhit∙printf∙putchar系统函数∙exit∙itoa字符函数∙isalnum∙isalpha∙iscntrl∙isdigit∙islower∙isascii∙isgraph∙isprint∙ispunct∙isspace∙isupper∙isxdigit∙toascii∙tolower∙toupper内存管理函数∙calloc∙free∙malloc∙reallocctype.h 字符函数isalnum功能:判断字符c是否为字母或数字说明:当c为数字0-9或字母a-z及A-Z时,返回非零值,否则返回零。
举例:printf("%c:%s\n",c,isalnum(c)?"yes":"no");isalpha功能:判断字符c是否为英文字母说明:当c为英文字母a-z或A-Z时,返回非零值,否则返回零。
C语言函数大全(C)
C语言函数大全(C)C语言是一种非常重要的编程语言,它是一种结构化,通用和高效的编程语言,适用于各种不同的应用领域。
C语言的重要性在于它已经成为了许多操作系统,编译器,数据库,GUI(图形用户界面)和其他高级语言的实现基础。
在本文中,我们将介绍C语言中的一些重要的函数,并简要描述它们的作用。
1. printf()该函数可以将输出的字符串和变量打印到屏幕上。
例如:printf("This is a string");,字符串“This is a string”将被打印到屏幕上。
2. scanf()该函数可以从屏幕上读取输入,并将其存储到变量中。
例如:scanf("%d", &x);,这将从屏幕上读取一个整数并将其存储在x变量中。
3. strlen()该函数可以计算字符串的长度(不包括空字符),并返回结果。
例如:strlen(str);,这将返回字符串“str”的长度。
4. strcmp()该函数可以比较两个字符串。
如果字符串相等则返回0,如果第一个字符串小于第二个字符串则返回一个负数,如果第一个字符串大于第二个字符串则返回一个正数。
例如:strcmp(str1, str2);,这将比较字符串“str1”和“str2”。
7. getchar()该函数从标准输入流中获取一个字符,并将其作为返回值返回。
例如:char c = getchar();,这将从键盘上获取一个字符并将其存储在变量“c”中。
8. putchar()该函数将一个字符输出到标准输出流中。
例如:putchar('a');,这将把字符‘a’输出到控制台。
9. isalpha()该函数检查给定的字符是否为字母。
如果是则返回非零值,否则返回0。
例如:isalpha('a');,这将返回非零值,因为‘a’是一个字母。
11. toupper()该函数返回给定字符的大写形式。
C语言库函数大全
C 语言库函数大全Turbo C 2.0 函数中文说明大全分类函数,所在函数库为ctype.hint isalpha(int ch) 若ch 是字母('A'-'Z','a'-'z')返回非0值,否则返回0int isalnum(int ch) 若ch 是字母('A'-'Z','a'-'z')或数字('0'-'9'),返回非0值,否则返回0 int isascii(int ch) 若ch 是字符(ASCII 码中的0-127)返回非0值,否则返回0 int iscntrl(int ch) 若ch 是作废字符(0x7F)或普通控制字符(0x00-0x1F),返回非0值,否则返回0 int isdigit(int ch) 若ch 是数字('0'-'9')返回非0值,否则返回0int isgraph(int ch) 若ch 是可打印字符(不含空格)(0x21-0x7E)返回非0值,否则返回0 int islower(int ch) 若ch 是小写字母('a'-'z')返回非0值,否则返回0int isprint(int ch) 若ch 是可打印字符(含空格)(0x20-0x7E)返回非0值,否则返回0 int ispunct(int ch) 若ch 是标点字符(0x00-0x1F)返回非0值,否则返回0int isspace(int ch) 若ch 是空格(' '),水平制表符('\t'),回车符('\r'), 走纸换行('\f'),垂直制表符('\v'),换行符('\n'), 返回非0值,否则返回0int isupper(int ch) 若ch 是大写字母('A'-'Z')返回非0值,否则返回0 int isxdigit(int ch) 若ch 是16进制数('0'-'9','A'-'F','a'-'f')返回非0值, 否则返回0 int tolower(int ch) 若ch 是大写字母('A'-'Z')返回相应的小写字母('a'-'z')int toupper(int ch) 若ch 是小写字母('a'-'z')返回相应的大写字母('A'-'Z')数学函数,所在函数库为math.h 、stdlib.h 、string.h 、float.hint abs(int i) 返回整型参数i 的绝对值double cabs(struct complex znum) 返回复数znum 的绝对值double fabs(double x) 返回双精度参数x 的绝对值long labs(long n) 返回长整型参数n 的绝对值double exp(double x) 返回指数函数ex 的值double frexp(double value,int *eptr) 返回value=x*2n 中x 的值,n 存贮在eptr 中 double ldexp(double value,int exp); 返回value*2exp 的值double log(double x) 返回logex 的值double log10(double x) 返回log10x 的值double pow(double x,double y) 返回xy 的值double pow10(int p) 返回10p 的值double sqrt(double x) 返回x 的开方double acos(double x) 返回x 的反余弦cos-1(x)值,x 为弧度double asin(double x) 返回x 的反正弦sin-1(x)值,x 为弧度double atan(double x) 返回x 的反正切tan-1(x)值,x 为弧度double atan2(double y,double x) 返回y/x 的反正切tan-1(x)值,y 的x 为弧度 double cos(double x) 返回x 的余弦cos(x)值,x 为弧度double sin(double x) 返回x 的正弦sin(x)值,x 为弧度double tan(double x) 返回x 的正切tan(x)值,x 为弧度 t o o l sdouble cosh(double x) 返回x 的双曲余弦cosh(x)值,x 为弧度double sinh(double x) 返回x 的双曲正弦sinh(x)值,x 为弧度double tanh(double x) 返回x 的双曲正切tanh(x)值,x 为弧度double hypot(double x,double y) 返回直角三角形斜边的长度(z), x 和y 为直角边的长度,z2=x2+y2 double ceil(double x) 返回不小于x 的最小整数double floor(double x) 返回不大于x 的最大整数void srand(unsigned seed) 初始化随机数发生器int rand() 产生一个随机数并返回这个数double poly(double x,int n,double c[]) 从参数产生一个多项式double modf(double value,double *iptr) 将双精度数value 分解成尾数和阶double fmod(double x,double y) 返回x/y 的余数double frexp(double value,int *eptr) 将双精度数value 分成尾数和阶double atof(char *nptr) 将字符串nptr 转换成浮点数并返回这个浮点数double atoi(char *nptr) 将字符串nptr 转换成整数并返回这个整数double atol(char *nptr) 将字符串nptr 转换成长整数并返回这个整数char *ecvt(double value,int ndigit,int *decpt,int *sign)将浮点数value 转换成字符串并返回该字符串char *fcvt(double value,int ndigit,int *decpt,int *sign)将浮点数value 转换成字符串并返回该字符串char *gcvt(double value,int ndigit,char *buf)将数value 转换成字符串并存于buf 中,并返回buf 的指针char *ultoa(unsigned long value,char *string,int radix)将无符号整型数value 转换成字符串并返回该字符串,radix 为转换时所用基数char *ltoa(long value,char *string,int radix)将长整型数value 转换成字符串并返回该字符串,radix 为转换时所用基数 char *itoa(int value,char *string,int radix) 将整数value 转换成字符串存入string,radix 为转换时所用基数double atof(char *nptr) 将字符串nptr 转换成双精度数,并返回这个数,错误返回0int atoi(char *nptr) 将字符串nptr 转换成整型数, 并返回这个数,错误返回0long atol(char *nptr) 将字符串nptr 转换成长整型数,并返回这个数,错误返回0double strtod(char *str,char **endptr)将字符串str 转换成双精度数,并返回这个数,long strtol(char *str,char **endptr,int base)将字符串str 转换成长整型数, 并返回这个数,int matherr(struct exception *e) 用户修改数学错误返回信息函数(没有必要使用)double _matherr(_mexcep why,char *fun,double *arg1p, double *arg2p,double retval)用户修改数学错误返回信息函数(没有必要使用)unsigned int _clear87() 清除浮点状态字并返回原来的浮点状态void _fpreset() 重新初使化浮点数学程序包unsigned int _status87() 返回浮点状态字目录函数,所在函数库为dir.h 、dos.hint chdir(char *path) 使指定的目录path (如:"C:\\WPS")变成当前的工作目录,成功返回0 int findfirst(char *pathname,struct ffblk *ffblk,int attrib)查找指定的文件,成功返回0pathname 为指定的目录名和文件名,如"C:\\WPS\\TXT" t o o l sffblk 为指定的保存文件信息的一个结构,定义如下:┏━━━━━━━━━━━━━━━━━━┓┃struct ffblk ┃┃{ ┃┃ char ff_reserved[21]; /*DOS 保留字*/┃┃ char ff_attrib; /*文件属性*/ ┃┃ int ff_ftime; /*文件时间*/ ┃┃ int ff_fdate; /*文件日期*/ ┃┃ long ff_fsize; /*文件长度*/ ┃┃ char ff_name[13]; /*文件名*/ ┃┃} ┃┗━━━━━━━━━━━━━━━━━━┛attrib 为文件属性,由以下字符代表┏━━━━━━━━━┳━━━━━━━━┓┃FA_RDONLY 只读文件┃FA_LABEL 卷标号┃┃FA_HIDDEN 隐藏文件┃FA_DIREC 目录 ┃┃FA_SYSTEM 系统文件┃FA_ARCH 档案 ┃┗━━━━━━━━━┻━━━━━━━━┛例:struct ffblk ff;findfirst("*.wps",&ff,FA_RDONLY);int findnext(struct ffblk *ffblk) 取匹配finddirst 的文件,成功返回0void fumerge(char *path,char *drive,char *dir,char *name,char *ext)此函数通过盘符drive(C:、A:等), 路径dir(\TC 、\BC\LIB 等), 文件名name(TC 、WPS 等),扩展名ext(.EXE 、.COM 等)组成一个文件名存与path 中.int fnsplit(char *path,char *drive,char *dir,char *name,char *ext)此函数将文件名path 分解成盘符drive(C:、A:等), 路径dir(\TC 、\BC\LIB 等), 文件名name(TC 、WPS 等),扩展名ext(.EXE 、.COM 等),并分别存入相应的变量中.int getcurdir(int drive,char *direc)此函数返回指定驱动器的当前工作目录名称。
C语言文件操作函数大全(超详细)
C语⾔⽂件操作函数⼤全(超详细)相关函数 open,fclose表头⽂件 #include<stdio.h>定义函数 FILE * fopen(const char * path,const char * mode);函数说明参数path字符串包含欲打开的⽂件路径及⽂件名,参数mode字符串则代表着流形态。
r 打开只读⽂件,该⽂件必须存在。
r+ 打开可读写的⽂件,该⽂件必须存在。
w 打开只写⽂件,若⽂件存在则⽂件长度清为0,即该⽂件内容会消失。
若⽂件不存在则建⽴该⽂件。
w+ 打开可读写⽂件,若⽂件存在则⽂件长度清为零,即该⽂件内容会消失。
若⽂件不存在则建⽴该⽂件。
a 以附加的⽅式打开只写⽂件。
若⽂件不存在,则会建⽴该⽂件,如果⽂件存在,写⼊的数据会被加到⽂件尾,即⽂件原先的内容会被保留。
a+ 以附加⽅式打开可读写的⽂件。
若⽂件不存在,则会建⽴该⽂件,如果⽂件存在,写⼊的数据会被加到⽂件尾后,即⽂件原先的内容会被保留。
复制代码代码如下:r Open text file for reading. The stream is positioned at the beginning of the file.r+ Open for reading and writing. The stream is positioned at the beginning of the file.w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file.w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is posi‐tioned at the beginning of the file.a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at theend of the file.a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file posi‐tion for reading is at the beginning of the file, but output is always appended to the end of the file.上述的形态字符串都可以再加⼀个b字符,如rb、w+b或ab+等组合,加⼊b 字符⽤来告诉函数库打开的⽂件为⼆进制⽂件,⽽⾮纯⽂字⽂件。
c函数大全
b=512
c=65535
strtoul(将字符串转换成无符号长整型数)
相关函数 atof,atoi,atol,strtod,strtol
表头文件 #include<stdlib.h>
定义函数 unsigned long int strtoul(const char *nptr,char **endptr,int base);
表头文件 #include<ctype.h>
定义函数 int toascii(int c)
函数说明 toascii()会将参数c转换成7位的unsigned char值,第八位则会被清除,此字符即会被转成ASCII码字符。
返回值 将转换成功的ASCII码字符值返回。
返回值 返回转换后的浮点型数。
附加说明 参考atof()。
范例 /*将字符串a,b,c 分别采用10,2,16 进制转换成数字*/
#include<stdlib.h>
mian()
{
char a[]=”1000000000”;
char b[]=”1000000000”;
int a,b,c;
char cs[10];
sscanf(szBuffer,"%6s_%d_%d_%d",cs,&a,&b,&c);
printf("%s_%d_%d_%d",cs,a,b,c+1);
return 0;
}
字符串转数字
atof(将字符串转换成浮点型数)
相关函数 atoi,atol,strtod,strtol,strtoul
C语言函数大全(c开头)
C语⾔函数⼤全(c开头)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 %s\n", str); /* free memory */free(str);return 0;}1、快速锁屏现代⼈的电脑充满了各种商业机密与隐私,上班时间喝个茶⽔都害怕电脑被“偷窥”。
电脑它⾃⼰也会保护⾃⼰哦,只要你离开之前按下快捷键:Windows+L,就能快速锁住电脑屏幕哦,妈妈再也不⽤担⼼我的机密泄露了2、误删恢复字打多了就容易⼿抖,尤其做⽂案的,有时候忙得眼花缭乱却⼀不⼩⼼把⽂字为误删了。
只要你未清空回收站,就能按快捷键:Ctrl+Z,进⾏撤回恢复。
C语言标准库函数大全
Page 1 of 22
博客园 社区 首页 新随笔 联系 管理 订阅
随笔- 208 文章- 0 评论14
c语言库函数大全--资料收集
Turbo C 2.0 函数中文说明大全
分类函数,所在函数库为ctype.h int isalpha(int ch) 若ch是字母('A'-'Z','a'-'z')返回非0值,否则返回0 int isalnum(int ch) 若ch是字母('A'-'Z','a'-'z')或数字('0'-'9'),返回非0值, 否则返回0 int isascii(int ch) 若ch是字符(ASCII码中的0-127)返回非0值,否则返回0 int iscntrl(int ch) 若ch是作废字符(0x7F)或普通控制字符(0x00-0x1F),返 回非0值,否则返回0 int isdigit(int ch) 若ch是数字('0'-'9')返回非0值,否则返回0 int isgraph(int ch) 若ch是可打印字符(不含空格)(0x21-0x7E)返回非0值, 否则返回0 int islower(int ch) 若ch是小写字母('a'-'z')返回非0值,否则返回0 int isprint(int ch) 若ch是可打印字符(含空格)(0x20-0x7E)返回非0值,否 则返回0 int ispunct(int ch) 若ch是标点字符(0x00-0x1F)返回非0值,否则返回0 int isspace(int ch) 若ch是空格(' '),水平制表符('\t'),回车符('\r'), 走纸换 行('\f'),垂直制表符('\v'),换行符('\n'), 返回非0值,否则返回0 int isupper(int ch) 若ch是大写字母('A'-'Z')返回非0值,否则返回0 int isxdigit(int ch) 若ch是16进制数('0'-'9','A'-'F','a'-'f')返回非0值, 否则 返回0 int tolower(int ch) 若ch是大写字母('A'-'Z')返回相应的小写字母('a'-'z') int toupper(int ch) 若ch是小写字母('a'-'z')返回相应的大写字母('A'-'Z')
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
函数名:cabs功能:计算复数的绝对值用法:double cabs(struct complex z);程序例:#include<stdio.h>#include<math.h>int 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);return0;}函数名:calloc功能:分配主存储器用法:void*calloc(size_t nelem,size_t elsize);程序例:#include<stdio.h>#include<alloc.h>int 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);return0;}函数名:ceil功能:向上舍入用法:double ceil(double x);程序例:#include<math.h>#include<stdio.h>int 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);return0;}函数名:cgets功能:从控制台读字符串用法:char*cgets(char*str);程序例:#include<stdio.h>#include<conio.h>int main(void){char buffer[83];char*p;/*There's space for80characters 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 for5characters 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);return0;}函数名:chdir功能:改变工作目录用法:int chdir(const char*path);程序例:#include<stdio.h>#include<stdlib.h>#include<dir.h>char 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);}return0;}函数名:_chmod,chmod功能:改变文件的访问方式用法:int chmod(const char*filename,int permiss);程序例:#include<sys\stat.h>#include<stdio.h>#include<io.h>void make_read_only(char*filename);int main(void){make_read_only("NOTEXIST.FIL");make_read_only("MYFILE.FIL");return0;}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<string.h>#include<fcntl.h>#include<io.h>int main(void){int handle;char buf[11]="0123456789";/*create text file containing10bytes*/handle=open("DUMMY.FIL",O_CREAT);write(handle,buf,strlen(buf));/*truncate the file to5bytes in size*/chsize(handle,5);/*close the file*/close(handle);return0;}函数名:circle功能:在给定半径以(x,y)为圆心画圆用法:void far circle(int x,int y,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 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();return0;}函数名:cleardevice功能:清除图形屏幕用法:void far cleardevice(void);程序例:#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;/*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();return0;}函数名:clearerr功能:复位错误标志用法:void clearerr(FILE*stream);程序例:#include<stdio.h>int 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);return0;}函数名:clearviewport功能:清除图形视区用法:void far clearviewport(void);程序例:#include<graphics.h>#include<stdlib.h>#include<stdio.h>#include<conio.h>#define CLIP_ON1/*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();return0;}函数名:_close,close功能:关闭文件句柄用法:int close(int handle);程序例:#include<string.h>#include<stdio.h>#include<fcntl.h>#include<io.h>main(){int handle;char buf[11]="0123456789";/*create a file containing10bytes*/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");}return0;}函数名:clock功能:确定处理器时间用法:clock_t clock(void);程序例:#include<time.h>#include<stdio.h>#include<dos.h>int main(void){clock_t start,end;start=clock();delay(2000);end=clock();printf("The time was:%f\n",(end-start)/CLK_TCK);return0;}函数名:closegraph功能:关闭图形系统用法:void far closegraph(void);程序例:#include<graphics.h>#include<stdlib.h>#include<stdio.h>#include<conio.h>int 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();return0;}函数名:clreol功能:在文本窗口中清除字符到行末用法:void clreol(void);程序例:#include<conio.h>int 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();return0;}函数名:clrscr功能:清除文本模式窗口用法:void clrscr(void);程序例:#include<conio.h>int 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();return0;}函数名:coreleft功能:返回未使用内存的大小用法:unsigned coreleft(void);程序例:#include<stdio.h>#include<alloc.h>int 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());return0;}函数名:cos功能:余弦函数用法:double cos(double x);程序例:#include<stdio.h>#include<math.h>int main(void){double result;double x=0.5;result=cos(x);printf("The cosine of%lf is%lf\n",x,result);return0;}函数名:cosh功能:双曲余弦函数用法:dluble cosh(double x);程序例:#include<stdio.h>#include<math.h>int main(void){double result;double x=0.5;result=cosh(x);printf("The hyperboic cosine of%lf is%lf\n",x,result);return0;}函数名:country功能:返回与国家有关的信息用法:struct COUNTRY*country(int countrycode,struct country*country);程序例:#include<dos.h>#include<stdio.h>#define USA0int main(void){struct COUNTRY country_info;country(USA,&country_info);printf("The currency symbol for the USA is:%s\n", country_info.co_curr);return0;}函数名:cprintf功能:送格式化输出至屏幕用法:int cprintf(const char*format[,argument,...]);程序例:#include<conio.h>int 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();return0;}函数名:cputs功能:写字符到屏幕用法:void cputs(const char*string);程序例:#include<conio.h>int 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();return0;}函数名:_creat creat功能:创建一个新文件或重写一个已存在的文件用法:int creat(const char*filename,int permiss);程序例:#include<sys\stat.h>#include<string.h>#include<fcntl.h>#include<io.h>int 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);/*write10bytes to the file*/write(handle,buf,strlen(buf));/*close the file*/close(handle);return0;}函数名:creatnew功能:创建一个新文件用法:int creatnew(const char*filename,int attrib);程序例:#include<string.h>#include<stdio.h>#include<errno.h>#include<dos.h>#include<io.h>int 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);}return0;}函数名:creattemp功能:创建一个新文件或重写一个已存在的文件用法:int creattemp(const char*filename,int attrib);程序例:#include<string.h>#include<stdio.h>#include<io.h>int 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);return0;}函数名:cscanf功能:从控制台执行格式化输入用法:int cscanf(char*format[,argument,...]);程序例:#include<conio.h>int 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);return0;}函数名:ctime功能:把日期和时间转换为字符串用法:char*ctime(const time_t*time);程序例:#include<stdio.h>#include<time.h>int main(void){time_t t;time(&t);printf("Today's date and time:%s\n",ctime(&t));return0;}函数名:ctrlbrk功能:设置Ctrl-Break处理程序用法:void ctrlbrk(*fptr)(void);程序例:#include<stdio.h>#include<dos.h>#define ABORT0int c_break(void){printf("Control-Break pressed.Program aborting...\n");return(ABORT);}int main(void){ctrlbrk(c_break);for(;;){printf("Looping...Press<Ctrl-Break>to quit:\n");}return0; }。