当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

西安交通大学:《VC++》课程教学资源(教案讲义)附录2 常用库函数

资源类别:文库,文档格式:DOC,文档页数:7,文件大小:113KB,团购合买
附录2常用库函数 Microsoft为应用程序设计人员提供了大量的库函数,其功能覆盖了程序设计的方方面 面,为每个程序员所必须掌握。在本附录中,我们选列了其中较常用的库函数,供读者查 询参考。为了节省篇幅,我们只列出了函数原型和简单的功能说明。如果在使用时对某库 函数的功能、参数设置和返回值等仍有疑问,可以直接查看MSDN中的有关说明。
点击下载完整版文档(DOC)

附录2常用库函数 附录2常用库函数 Microsoft c为应用程序设计人员提供了大量的库函数,其功能覆盖了程序设计的方方面 面,为每个程序员所必须掌握。在本附录中,我们选列了其中较常用的库函数,供读者查 询参考。为了节省篇幅,我们只列出了函数原型和简单的功能说明。如果在使用时对某库 函数的功能、参数设置和返回值等仍有疑问,可以直接查看MSDN中的有关说明 1.分类库函数,原型均在头文件 ctype. h中。这组库函数实际上均为带参数的宏。 原型: int isalpha(intc) 功能:如果c为字母返回非0值,否则返回0。 原型: int isdigit(intc) 功能:如果c为数字返回非0值,否则返回。 原型: int isalnun(intc) 功能:如果c为字母或数字返回非0值,否则返回0 原型: int islower(intc); int isupper (int c): 功能:如果c为小写(大写)字母返回非0值,否则返回0。 原型: Int isprint(intc) 功能:如果c为可打印字符(包括字母、数字、空格和各种符号等)返回非0值,否则返 回 原型: Int Isspace(intc) 功能:如果c为空格、制表符、回车换行符等则返回非0值,否则返回0。 原型: int tolower( int ch) int toupper (int ch) 功能:将字符转换为小写或大写字符 2.目录操作函数,用于在程序中处理文件目录系统,原型均在头文件 direct. h中 原型: int chdir( const char* dirname) 功能:改变当前目录。 原型: int chdrive( int drive) 功能:改变当前驱动器。 原型:char* getcwd(char* buffer, int maxlen); 功能:读取当前目录。 RA: char *getdcwd int drive. char *buffer, int maxlen ): 功能:从指定驱动器的读取当前目录

附录 2 常用库函数 343 附录 2 常用库函数 Microsoft C 为应用程序设计人员提供了大量的库函数,其功能覆盖了程序设计的方方面 面,为每个程序员所必须掌握。在本附录中,我们选列了其中较常用的库函数,供读者查 询参考。为了节省篇幅,我们只列出了函数原型和简单的功能说明。如果在使用时对某库 函数的功能、参数设置和返回值等仍有疑问,可以直接查看 MSDN 中的有关说明。 1.分类库函数,原型均在头文件 ctype.h 中。这组库函数实际上均为带参数的宏。 原型: int isalpha(int c); 功能: 如果 c 为字母返回非 0 值,否则返回 0。 原型: int isdigit(int c); 功能: 如果 c 为数字返回非 0 值,否则返回。 原型: int isalnum(int c); 功能: 如果 c 为字母或数字返回非 0 值,否则返回 0。 原型: int islower(int c); int isupper(int c); 功能: 如果 c 为小写(大写)字母返回非 0 值,否则返回 0。 原型: int isprint(int c); 功能: 如果 c 为可打印字符(包括字母、数字、空格和各种符号等)返回非 0 值,否则返 回 0。 原型: int isspace(int c); 功能: 如果 c 为空格、制表符、回车换行符等则返回非 0 值,否则返回 0。 原型: int tolower(int ch); int toupper(int ch); 功能: 将字符转换为小写或大写字符。 2.目录操作函数,用于在程序中处理文件目录系统,原型均在头文件 direct.h 中。 原型: int _chdir( const char *dirname ); 功能: 改变当前目录。 原型: int _chdrive( int drive ); 功能: 改变当前驱动器。 原型: char *_getcwd( char *buffer, int maxlen ); 功能: 读取当前目录。 原型: char *_getdcwd( int drive, char *buffer, int maxlen ); 功能: 从指定驱动器的读取当前目录

附录2常用库函数 原型 getdrive( void 功能:读取当前磁盘驱动器。 原型: int mkdir( const char* dirname); 功能:建立目录。 原型: int rmdir( const char* dirname) 功能:删除目录。 RRA: void searchenv const char *filename, const char *varname, char*pathname) 功能:按指定路径查找给出的文件 3.进程和环境控制库函数,原型均在头文件 Process h或 Stdlib.h中。 原型: void abort(void); 功能:异常终止一个进程。 原型: void exit( int status); 功能:中止程序。 原型: Int system(char* command) 功能:在不退出程序的情况下直接启动DOS的命令行。可以使用此函数运行其它程序, 然后在返回原来的应用程序。 4.类型转换库函数,除注明者外,原型均在头文件 stdlib.h中 原型: int atol(char*s) double atof (char *s) 功能:将字符串分别转换为整型数、长整型数和双精度型数。atof()的原型在头文件 RRE: char* itoa (int value, char *string, int radix) char Itoa (long value, char *string, int radix 功能:整型或长整型数值转换为字符串 5.输入输出库函数,除注明者外,原型均在头文件 stdio. h中。 原型: int getchar(void) 功能:从标准输入设备(键盘,下同)读一个字符。 原型: int getch(void); int getche(void): 功能:从标准输入设备(键盘,下同)读一个字符 原型: int khit(void) 功能:检查当前按键是否有效。原型在头文件 conio. h中。 原型: int putchar(intc) 功能:向标准输出设备(显示屏,下同)写一个字符 原型: int putch(intc); 功能:向控制台写一个字符

附录 2 常用库函数 344 原型: int _getdrive( void ); 功能: 读取当前磁盘驱动器。 原型: int _mkdir( const char *dirname ); 功能: 建立目录。 原型: int _rmdir( const char *dirname ); 功能: 删除目录。 原型: void _searchenv( const char *filename, const char *varname, char *pathname ); 功能: 按指定路径查找给出的文件。 3.进程和环境控制库函数,原型均在头文件Process.h或Stdlib.h中。 原型: void abort(void); 功能: 异常终止一个进程。 原型: void exit(int status); 功能: 中止程序。 原型: int system(char *command); 功能: 在不退出程序的情况下直接启动DOS的命令行。可以使用此函数运行其它程序, 然后在返回原来的应用程序。 4.类型转换库函数,除注明者外,原型均在头文件stdlib.h中。 原型: int atoi(char *s); long atol(char *s); double atof(char *s); 功能:将字符串分别转换为整型数、长整型数和双精度型数。atof()的原型在头文件 math.h中。 原型: char *_itoa(int value,char *string,int radix); char *_ltoa(long value, char *string,int radix); 功能: 整型或长整型数值转换为字符串。 5.输入/输出库函数,除注明者外,原型均在头文件stdio.h中。 原型:int getchar( void ); 功能:从标准输入设备(键盘,下同)读一个字符。 原型: int getch(void); int getche(void); 功能: 从标准输入设备(键盘,下同)读一个字符。 原型: int _kbhit( void ); 功能: 检查当前按键是否有效。原型在头文件conio.h中。 原型: int putchar( int c ); 功能: 向标准输出设备(显示屏,下同)写一个字符。 原型: int _putch( int c ); 功能: 向控制台写一个字符

附录2常用库函数 RA: int printf( const char *format [ argument].) 功能:向标准输出设备进行格式化输出 RRE: int scanf const char*format[, argument]..) 功能:从标准输入设备进行格式化输入。 原型:char*gets( char *buffer); 功能:从标准输人设备输入字符串。 原型: Int puts( const char* string); 功能:向标准输出设备写字符串 原型: int ungetch(intc) 功能:将一个字符退回键盘缓冲区,下次用 getch()等函数即可读此字符。 RA: FILE*fopen const char*filename, const char *mode int fclose File *stream 功能:打开和关闭流式文件。 原型: int fgetc(FILE* stream) int getc( FILE *stream fputc( int c, FILE int putc( int c, FILE*stream): 功能:从文件中读一个字符,或向文件中写一个字符。 RR: char *fgets char *string, int n, FILE*stream int fputs( const char*string, FILE*stream ): 功能:文件字符串读写 RRE: int fprintf( FILE*stream, const char*format[, argument].): int fscanf( FILE*stream, const char *format[, argument I 功能:文件格式化读写 R 4: size t fread void*buffer size t size size t count. File*stream size t fwrite const void *buffer size t size. size t count fIle*stream 功能:文件成块读写 RRA: int fseek FILE *stream, long offset, int origin ) long ftell( FILE *stream): 功能:文件指针定位。 原型: int feof(FILE* stream); 功能:测试文件是否结東 原型: Int ungetc(ntc,FIE* sstream) 功能:将一个字符退回文件缓冲区中,下次用 fgetc()等函数即可读此字符 RA: int rename const char *oldname, const char*newname 功能:修改文件名 原型: int unlink( const char* filename) 功能:删除文件。原型在头文件 Stdio.h和ioh中

附录 2 常用库函数 345 原型: int printf( const char *format [, argument]... ); 功能: 向标准输出设备进行格式化输出。 原型: int scanf( const char *format [,argument]... ); 功能: 从标准输入设备进行格式化输入。 原型: char *gets( char *buffer ); 功能: 从标准输人设备输入字符串。 原型: int puts( const char *string ); 功能: 向标准输出设备写字符串。 原型: int _ungetch( int c ); 功能: 将一个字符退回键盘缓冲区,下次用getch()等函数即可读此字符。 原型: FILE *fopen( const char *filename, const char *mode ); int fclose( FILE *stream ); 功能: 打开和关闭流式文件。 原型: int fgetc( FILE *stream ); int getc( FILE *stream ); int fputc( int c, FILE *stream ); int putc( int c, FILE *stream ); 功能: 从文件中读一个字符,或向文件中写一个字符。 原型: char *fgets( char *string, int n, FILE *stream ); int fputs( const char *string, FILE *stream ); 功能: 文件字符串读写。 原型: int fprintf( FILE *stream, const char *format [, argument ]...); int fscanf( FILE *stream, const char *format [, argument ]... ); 功能: 文件格式化读写。 原型: size_t fread( void *buffer, size_t size, size_t count, FILE *stream ); size_t fwrite( const void *buffer, size_t size, size_t count, FILE *stream ); 功能: 文件成块读写。 原型: int fseek( FILE *stream, long offset, int origin ); long ftell( FILE *stream ); 功能: 文件指针定位。 原型: int feof( FILE *stream ); 功能: 测试文件是否结束。 原型: int ungetc( int c, FILE *stream ); 功能: 将一个字符退回文件缓冲区中,下次用fgetc()等函数即可读此字符。 原型: int rename( const char *oldname, const char *newname ); 功能: 修改文件名。 原型: int _unlink( const char *filename ); 功能: 删除文件。原型在头文件Stdio.h和io.h中

附录2常用库函数 6.存储分配库函数,原型均在头文件 malloc. h中 原型:void* malloc( size t size) 功能:按字节申请存储空间 原型:void* calloc( size t num, size t size) 功能:成组申请存储空间。 RA: void *realloc( void*memblock size t size 功能:修改已动态分配的存储块大小。 原型: void free(void* enblock); 功能:释放动态申请的存储块。 内存操作函数,除特别说明者外,原型均在头文件 memory. h和 Istring h中 RRA: void*memset( void*dest, int c size t count 功能:将一段内存均置为给定的内容。 RRE: int memcmp( const void*bufl, const void*buf2, size t count): nt memicmp const void *bufl, const void*buf2, unsigned int count 功能:比较两段存储空间的内容。 memicmp()不区分大、小写字母 R4: void*memchr const void *buf. int c size t count 功能:在指定内存单元中查找字符。。 RRE: void*memcpy( void*dest, const void*src, size t count ): void *memmove void *dest. const void *src size t count 功能:复制一段给定的内存单元内容。 memcpy()与 memmove()的复制方向不同,这 在源空间和目标空间有重叠时特别重要。 8.字符串操作库函数,原型均在头文件 string h中。这组库函数甚多,这里只选列了其中较 常用的几个 原型:char* street(char* string,intc); char* strnset( char*string, int c, size t count): 功能:将字符串中的字符设置为给定值。 RRA: char *strcpy char *strDestination, const char*strSource); char *strncpy char *strDest, const char *str Source, size t count 功能:字符串拷贝。 RR4: char *strcat( char *strDest, const char *strSource char *strncat( char *strDest, const char *strSource, size t count): 功能:将字符串 i str Source添加在字符串 str dest之后 原型:char* strlwr( char*string); char* strupr char*string 功能:将字符串中的字母字符均转换为小写/大写字母。 原型:char* strrev(char* string); 功能:反转字符串的内容 原型: char *strchr( const char* string,intc)

附录 2 常用库函数 346 6.存储分配库函数,原型均在头文件malloc.h中。 原型: void *malloc( size_t size ); 功能: 按字节申请存储空间。 原型: void *calloc( size_t num, size_t size ); 功能: 成组申请存储空间。 原型: void *realloc( void *memblock, size_t size ); 功能: 修改已动态分配的存储块大小。 原型: void free( void *memblock ); 功能: 释放动态申请的存储块。 7.内存操作函数,除特别说明者外,原型均在头文件memory.h 和string.h中。 原型: void *memset( void *dest, int c, size_t count ) ; 功能: 将一段内存均置为给定的内容。 原型: int memcmp( const void *buf1, const void *buf2, size_t count ); int _memicmp( const void *buf1, const void *buf2, unsigned int count ); 功能: 比较两段存储空间的内容。_memicmp()不区分大、小写字母。 原型: void *memchr( const void *buf, int c, size_t count ); 功能: 在指定内存单元中查找字符。。 原型: void *memcpy( void *dest, const void *src, size_t count ); void *memmove( void *dest, const void *src, size_t count ); 功能: 复制一段给定的内存单元内容。memcpy()与memmove()的复制方向不同,这 在源空间和目标空间有重叠时特别重要。 8.字符串操作库函数,原型均在头文件string.h中。这组库函数甚多,这里只选列了其中较 常用的几个。 原型: char *_strset( char *string, int c ); char *_strnset( char *string, int c, size_t count ); 功能: 将字符串中的字符设置为给定值。 原型: char *strcpy( char *strDestination, const char *strSource ) ; char *strncpy( char *strDest, const char *strSource, size_t count ); 功能: 字符串拷贝。 原型: char *strcat( char *strDest, const char *strSource ); char *strncat( char *strDest, const char *strSource, size_t count ); 功能: 将字符串strSource 添加在字符串strDest之后。 原型: char *_strlwr( char *string ); char *_strupr( char *string ); 功能: 将字符串中的字母字符均转换为小写/大写字母。 原型: char *_strrev( char *string ); 功能: 反转字符串的内容。 原型: char *strchr( const char *string, int c );

附录2常用库函数 功能:在字符串 string中查找指定字符c RNA: char *strstr const char *string, const char *str Set) 功能:在字符串中查找指定子字符串。 RRE: int strcmp const char *stringl, const char *string2): int stricmp( const char *stringl, const char *string2): int strncmp( const char *stringl, const char *string2, size t count int strnicmp( const char *stringl, const char *string2, size t count 功能:比较两个字符串。 stricmp()在比较时不区对大小写字母; strncmp()仅比较两 字符串的前 maxlen位; strnicmp()仅比较两字符串的前 maxlen位,且比较时不区 分大小写字母。如果两字符串相同,则返回地否则返回非0值 原型: size t strlen( const char* string) 功能:求字符串长度。 9.数学运算库函数,原型均在头文件 math. h 原型: int abs(intn) double fabs (double x) long labs (long x): 功能:求绝对值 原型: double cabs( struct complex Z) 功能:求复数的模。 原型: double sin( double); double cos (double x) double tan ( double x) double asin (double x) double acos double x) double atan (double x) double atan2(double y, double x): 功能:求三角函数和反三角函数 原型: double sinh( double); double tanh ( double x) 功能:求双曲函数。 原型: double exp( double) double log( double x) double pow( double x, double y double sqrt( double x 功能:求指数、对数、幂函数和平方根。 原型: Int max(inta,intb);

附录 2 常用库函数 347 功能: 在字符串string中查找指定字符c 原型: char *strstr( const char *string, const char *strCharSet ); 功能: 在字符串中查找指定子字符串。 原型: int strcmp( const char *string1, const char *string2 ); int _stricmp( const char *string1, const char *string2 ); int strncmp( const char *string1, const char *string2, size_t count ); int _strnicmp( const char *string1, const char *string2, size_t count ); 功能: 比较两个字符串。stricmp()在比较时不区对大小写字母;strncmp()仅比较两 字符串的前maxlen位;strnicmp()仅比较两字符串的前maxlen位,且比较时不区 分大小写字母。如果两字符串相同,则返回地否则返回非0值。 原型: size_t strlen( const char *string ); 功能: 求字符串长度。 9.数学运算库函数,原型均在头文件math.h。 原型: int abs( int n ); double fabs(double x); long labs(long x); 功能: 求绝对值。 原型: double _cabs( struct _complex z ); 功能: 求复数的模。 原型: double sin(double); double cos(double x); double tan(double x); double asin(double x); double acos(double x); double atan(double x); double atan2(double y, double x); 功能: 求三角函数和反三角函数。 原型: double sinh(double); double cosh(double x); double tanh(double x); 功能: 求双曲函数。 原型: double exp(double); double log(double x); double log10(double x); double pow(double x, double y); double sqrt(double x); 功能: 求指数、对数、幂函数和平方根。 原型: int max(int a,int b);

附录2常用库函数 int min (int a, int b) 功能:求两数中的较大者或较小者。这两个库函数均为定义于头文件则州地h中的带参数 的宏 原型: double 功能:计算直角三角形斜边的长 10.时间函数,原型均在头文件 time. h中。 原型: time t time( time t*timer) 功能:取当前系统时间。其中类型 time t(相当于 long int)存放自1970年1月1日午夜起流 逝的秒数 原型: char *ctime( const time t *timer); 功能:将以 time t格式存放的时间转换为相应的字符串,结果为一静态字符串的地址,其 格式形如:“ Wed Jan0202:03:551980un”。 RR: double difftime( time t timer1, time t timer) 功能:求从 timer0到 Timers之间以秒为单位的时间间隔 原型: struct tm *localtime( const time t↑imer); struct tm*mtime( const time t*timer ) 功能:将以 time t类型表示的时间值转换为以 struct tm格式表示的时间。 struct tm的格式 为 struct tm i int tm sec; /*seconds after the minute-[0, 59]*/ Int tm / minutes after the hour-[0, 59]*/ urs since mIdnig int tm mday: /day of the month-[1, 31]*/ int tm mon; /*months since January -[0, 11]*/ int tm year; / years since 1900*/ int tm wday; /*days since Sunday -[0, 6]*/ int tm yday; /*days uary I-[0,365]*/ int tm isdst; /*daylight savings time flag */ 原型: time t mktime( struct tm* timepti) 功能:将 struct tm格式的时间转换为tmet格式的时间 原型:char* asctime( const struct tm timeptr); 功能:将 struct tm格式的时间转换为字符串(参看 ctime()函数)。 11.随机数发生器库函数,原型均在头文件 stdlib. h中 原型: int rand(void); 功能:产生一个范围在0~ RAND MAX(0x7mf)之间的随机数。 原型: void srand( unsigned int seed)

附录 2 常用库函数 348 int min(int a,int b); 功能: 求两数中的较大者或较小者。这两个库函数均为定义于头文件则州地 h中的带参数 的宏。 原型: double _hypot( double x, double y ); 功能: 计算直角三角形斜边的长。 10.时间函数,原型均在头文件 time.h 中。 原型: time_t time ( time_t *timer ); 功能: 取当前系统时间。其中类型 time_t(相当于long int)存放自1970年1月1日午夜起流 逝的秒数。 原型: char *ctime ( const time_t *timer ); 功能: 将以 time_t 格式存放的时间转换为相应的字符串,结果为一静态字符串的地址,其 格式形如:“Wed Jan 02 02:03:55 1980\n”。 原型: double difftime ( time_t timer1, time_t timer0 ); 功能: 求从timer0到timer1之间以秒为单位的时间间隔。 原型: struct tm *localtime ( const time_t *timer ); struct tm *gmtime( const time_t *timer ); 功能: 将以 time_t 类型表示的时间值转换为以 struct tm 格式表示的时间。struct tm 的格式 为: struct tm { int tm_sec; /* seconds after the minute - [0,59] */ int tm_min; /* minutes after the hour - [0,59] */ int tm_hour; /* hours since midnight - [0,23] */ int tm_mday; /* day of the month - [1,31] */ int tm_mon; /* months since January - [0,11] */ int tm_year; /* years since 1900 */ int tm_wday; /* days since Sunday - [0,6] */ int tm_yday; /* days since January 1 - [0,365] */ int tm_isdst; /* daylight savings time flag */ }; 原型: time_t mktime ( struct tm *timeptr ); 功能: 将struct tm 格式的时间转换为 time_t 格式的时间。 原型: char *asctime( const struct tm *timeptr ); 功能: 将 struct tm 格式的时间转换为字符串(参看 ctime()函数)。 11.随机数发生器库函数,原型均在头文件stdlib.h中。 原型: int rand( void ); 功能: 产生一个范围在0~RAND_MAX(0x7fff〕之间的随机数。 原型: void srand( unsigned int seed );

附录2常用库函数 功能:根据给定的初值初始化随机发生器。例如: time t timer time(&timer) srand((unsigned int )timer); 用当前系统时间初始化随机数发生器,用以得出不重复的随机数序列

附录 2 常用库函数 349 功能: 根据给定的初值初始化随机发生器。例如: time_t timer; time (&timer); srand ((unsigned int)timer); 用当前系统时间初始化随机数发生器,用以得出不重复的随机数序列

点击下载完整版文档(DOC)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
已到末页,全文结束
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有