Microsof t运行库按字母顺序排列参考
abort
abs
access,waccess
acos
allcca
asctime,wasctime
asin
assert
atan, atan2
atexit
tof,atoi,atoi64,atoll
abort
终止当前的进程并返回一个错误代码。
void abort(void);
例程 需要的头文件 兼容性
abort <process.h>或<stdlib.h> ANSI,Win NT,Win 95
对于另外兼容性的信息,参见引言中的兼容性
库
LIBC.LIB 单线程静态库,零售版本
LIBCMT.LIB 多线程静态库,零售版本
MSVCRT.LIB MSVCRT.DLL的输入库,零售版本
返回值
abort不将控制返回给调用进程。缺省地,它终止当前进程并返回退出码3。
说明abort例程打印消息揳bnormal program termination?然后调用raise(SIGABRT)。响应SIGABRT信号所发生的动作取决于在调用signal函数之前为该信号确定的动作。缺省的SIGABRT动作是调用进程以退出码3终止,返回控制给调用进程或操作系统。abort不刷新流缓冲区或做atexit/onexit处理。
abort基于调用例程的应用程序的类型来确定消息的目的。控制台应用程序总是经由stderr接收消息。在单线程或多线程Windows应用程序中,abort调用Windows
MessageBox API 函数来建立一个消息框显示该消息和一个OK按钮,当用户选择OK时,该程序立即终止。
当应用程序与运行库的一个调试版本链接时,abort建立一个有三个按钮:Abort、Retry和Ignore的消息框。如果用户选择Abort,该程序立即终止;如果用户选择Rerty,调用调试器,如果允许及时调试则调试该程序;如果用户选择Ignore,abort继续它的正常执行,建立一个带OK按钮的消息框。有关更多的信息,参见联机帮助《Visual
C++程序员指南》中的撌褂肅运行库调试支持敗@?* ABORT.C: this program tries to open a
* file and aborts if the attempt fails. */#include <stdio.h>#include
<stdlib.h>void main( void ){ FILE *stream; if( (stream = fopen(
"NOSUCHF.ILE", "r" )) == NULL )
{
perror( "Couldn't open file" );
abort();
}
else
fclose( stream );
}
输出结果 Couldn't open file: No such file or directory
abnormal program termination
参见
exec函数概述,exit,raise,signal,spawn函数概述,DEBUG
返回顶端
abs
计算绝对值。
int abs(int n);
例程 需要的头文件 兼容性
abs <stdlib.h>或<math.h> ANSI,Win NT,Win 95
对于另外兼容性的信息,参见引言中的兼容性
库
LIBC.LIB 单线程静态库,零售版本
LIBCMT.LIB 多线程静态库,零售版本
MSVCRT.LIB MSVCRT.DLL的输入库,零售版本
返回值
abs函数返回其参数的绝对值。没有错误返回。
参数
n
整数值。
例子
/* ABS.C: This program computes and displays
* the absolute values of several numbers.
*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
void main( void )
{
int ix = -4,
iy;longlx = -41567L, ly;
double dx = -3.141593, dy;
iy = abs( ix );
printf( "The absolute value of %d is %d\n", ix, iy);
ly = labs( lx );
printf( "The absolute value of %ld is %ld\n", lx, ly);
dy = fabs( dx );
printf( "The absolute value of %f is %f\n", dx, dy);
}
输出结果
The absolute value of -4 is 4
The absolute value of -41567 is 41567
The absolute value of -3.141593 is 3.141593
参见
cabs,fabs,labs
返回顶端
access,waccess
确定文件访问许可权。
int access(const char *path,int mode);
int waccess(const wchart *path,int mode);
例程 需要的头文件 兼容性
access <io.h> Win NT,Win 95
Waccess <wchar.h>或<io.h> Win NT
对于另外兼容性的信息,参见引言中的兼容性
库
LIBC.LIB 单线程静态库,零售版本
LIBCMT.LIB 多线程静态库,零售版本
MSVCRT.LIB MSVCRT.DLL的输入库,零售版本
返回值
如果该文件有给定的模式,每个这样的函数返回0。如果指定的文件不存在或在给定的模式下不能访问,该函数返回-1,在这种情况下,errno设置如下:
EACCES
访问拒绝:文件的许可权设置为不允许指定的访问。
ENOENT
文件名或路径未找到。
参数
path
文件或目录路径。
Mode
许可权设置。
说明
当与文件使用时,access函数确定的文件是否存在,且能否以mode值指定的模式访问。
当与目录使用时,access仅确定指定的目录是否存在。在Windows
NT中,所有目录都可读和写访问。
mode值 检测文件条件
00 仅存在
02 写许可
04 读许可
06 读和写许可
waccess是 access的宽字符版本;waccess的path参量是宽字符串。waccess和access行为在其它方法一致。
通用文本例程映射
TCHAR.H例程 UNCODE&MBCS 未定义 MBCS已定义 UNICODE已定义
Taccess access access waccess
例子
/* ACCESS.C: This example uses access to check the
* file named "ACCESS.C" to see if it exists and if
* writing is allowed.
*/
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
void main( void )
{
/* Check for existence */
if( (access( "ACCESS.C", 0 )) != -1 )
{
printf( "File ACCESS.C exists\n" );
/* Check for write permission */
if( (access( "ACCESS.C", 2 )) != -1 )
printf( "File ACCESS.C has write permission\n" );
}
}
输出结果
File ACCESS.C exists
File ACCESS.C has write permission
参见
chmod,fstat,open,stat
返回顶端
acos
计算反余弦值。
double acos(double x);
例程 需要的头文件 可选的头文件 兼容性
acos <math.h> <eror.h> ANSI,Win NT,Win 95
对于另外兼容性的信息,参见引言中的兼容性
库 LIBC.LIB单线程静态库,零售版本
LIBCMT.LIB 多线程静态库,零售版本
MSVCRT.LIB MSVCRT.DLL的输入库,零售版
本返回值
acos函数返回0到π弧度的反余弦值,如果x小于-1或大于1,acos返回一个无穷值(如同静止的NaN)。可以使用matherr例程修改该错误处理。
参数
x
-1到1之间的值,可计算其反余弦值。
例子
/* ASINCOS.C: This program prompts for a value in the range
* -1 to 1. Input values outside this range will produce
* DOMAIN error messages. If a valid value is entered, the
* program prints the arcsine and the arccosine of that value.
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
void main( void )
{
double x, y;
printf( "Enter a real number between -1 and 1: " );
scanf( "%lf", &x );
y = asin( x );
printf( "Arcsine of %f = %f\n", x, y );
y = acos( x );
printf( "Arccosine of %f = %f\n", x, y );
}
输出结果
Enter a real number between -1 and 1: .32696
Arcsine of 0.326960 = 0.333085
Arccosine of 0.326960 = 1.237711
参见
asin,atan,cos,matherr,sin,tan
返回顶端
allcca
分配栈上的存储器。
void *alloc(sizet size);
例程 需要的头文件 兼容性
allcca <malloc.h> Win NT,Win 95
对于另外兼容性的信息,参见引言中的兼容性
库
LIBC.LIB 单线程静态库,零售版本
LIBCMT.LIB 多线程静态库,零售版本
MSVCRT.LIB MSVCRT.DLL的输入库,零售版本
返回值
alloca例程返回分配的空间的void指针,它确保适合于任何类型的对象进行存储,为了获取非char的其它类型的指针,在返回值上使用一个类型造型。如果该空间不能分配,产生一个栈溢出异常。
参数
size
从栈分配的字节。
说明
alloc从程序栈分配size字节,该分配的空间在调用函数退出时自动释放,因此不传送alloca返回的指针值作为一个释放的参数。
在一个异常处理器(EH)中显式调用alloca存在限制。运行在x86类处理器上的EH例程在它们自己的存储器 框架斨胁僮?它们在存储器空间中执行它们的功能,该存储器空间不是基于该函数的栈指针的当前位置。最常用的实现包括Windows
NT结构的异常处理(SEH)和C++ catch子句表达式。因此,在如下场合中显式调用alloca导致在返回到调用EH例程时程序失败:
.Windows NT EH 异常过滤器表达式:except(alloca());
.Windows NT SEH 最终异常处理器:finally{alloca()};
.C++ EH catch子句表达式。
但alloca可以从一个EH例程或从一个应用支持的回调(callback)中直接调用,该回调是通过上述所列的EH场合之一获取调用的。
参见
calloc,malloc,realloc
返回顶端
asctime,wasctime
将一个tm时间结构转换成一个字符串。
char *asctime(const struct tm *timeptr);
wchart *wasctime(const struct tm *timeptr);
例程 需要的头文件 兼容性
asctime <time.h>或 ANSI,Win NT,Win 95
Wasctime <time.h>或<wchar.h> Win NT,Win 95
对于另外兼容性的信息,参见引言中的兼容性
库
LIBC.LIB 单线程静态库,零售版本
LIBCMT.LIB 多线程静态库,零售版本
MSVCRT.LIB MSVCRT.DLL的输入库,零售版本
返回值
asctime返回该结果字符串的一个指针;wasctime返回该结果宽字符串的一个指针。没有错误返回值。
Timeptr
时间/日期结构。
说明
asctime函数把作为一个结构存储的时间转换成一个字符串。timeptr值通过调用gmtime或localtime获取,这两个函数都返回一个tm结构的指针,该结构定义在TIME.H中。
timeptr域 值
tmhour 自午夜起的小时(0-23)。
Tmisdst 如果夏令时起作用则为正数;如果夏令时不起作用则为0;如果夏令时状态未知,则为负数。C运行库假设采用美国的规则实现夏令时(DST)的计算。
Tmmday 日号(1-31)。
Tmmin 分钟(0-59)。
Tmmon 月份(0-11,1月=0)。
Tmsec 秒钟(0-59)。
Tmwday 星期(0-6,星期日=0)。
Tmyday 天数(0-365,1月1日=0)。
Tmyear 年份(当前年-1900)。
转换的字符串也根据本地时区设置进行相应调整,有关配置本地时间以及详细定义时区环境和全局变量的信息,参见time,ftime和localtime函数。
由asctime产生的设置包含26个字符,并有格式:
Wed Jan 02 02:03:55 1980\n\0
其使用24小时制,所有域具有固定宽度。换行字符和空字符出现在该字符串的最后两个位置上。asctime使用单个静态分配的缓冲区保存返回值。这个函数的每次调用都消毁前面调用的结果。
wasctime是asctime的宽字符版本,wasctime和asctime行为在其它方面是一致的。
通用文本例程映射
TCHAR.H例程 UNCODE&MBCS未定义 MBCS被定义 UNICODE被定义
Tasctime asctime asctimewasctime
例子
/* ASCTIME.C: This program places the system time
* in the long integer aclock, translates it into the
* structure newtime and then converts it to string
* form for output, using the asctime function.
*/
#include <time.h>
#include <stdio.h>
struct tm *newtime;
timet aclock;
void main( void )
{
time( &aclock );/* Get time in senconds */
newtime = localtime( &aclock ); /* Convert time to struct */
/* tm form */
/* Print local time as a string */
printf( "The current data and time are: %s", asctime(
newtime ) );
}
输出结果
The current data and time are: Sun May 01 20:27:01 1994
参见
ctime,ftime,gmtime,localtime,time,tzse
返回顶端
asin
计算反正弦值。
double asin(double x);
例程 需要的头文件 兼容性
asin <math.h>ANSI,Win NT Win 95
对于另外兼容性的信息,参见引言中的兼容性
库
LIBC.LIB 单线程静态库,零售版本
LIBCMT.LIB 多线程静态库,零售版本
MSVCRT.LIB MSVCRT.DLL的输入库, 零售版本
返回值
asin函数返回范围在-π/2到π/2弧度的x的反正弦值,如果x小于-1或大于1,asin返回一个无穷值(如同静止的NaN)。可以使用matherr例程修改该错误处理。
参数
x
可计算其反正弦的值。
例子
/* ASINCOS.C: This program prompts for a value in the range
* -1 to 1. Input values outside this range will produce
* DOMAIN error messages. If a valid value is entered, the
* program prints the arcsine and the arccosine of that value.
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
void main( void )
{
double x, y;
printf( "Enter a real number between -1 and 1: " );
scanf( "%lf", &x );
y = asin( x );
printf( "Arcsine of %f = %f\n", x, y );
y = acos( x );
printf( "Arccosine of %f = %f\n", x, y );
}
输出结果
Enter a real number between -1 and 1: .32696
Arcsine of 0.326960 = 0.333085
Arccosine of 0.326960 = 1.237711
参见
acos,atan,cos,matherr,sin,
返回顶端
tanassert
对一个表达式求值,当结果为FALSE时,打印一个诊断消息并终止该程序。
void assert(int expression);
void assert(int expression);
例程 需要的头文 件兼容性
assert <assert.h>ANSI,Win NT, Win 95
对于另外兼容性的信息,参见引言中的兼容性
库
LIBC.LIB 单线程静态库,零售版本
LIBCMT.LIB 多线程静态库,零售版本
MSVCRT.LIBMSVCRT.DLL的输入库,零售版本
返回值
无
参数
expression
求值为非0或0的表达式(包括指针)。
说明
ANSI的assert函数一般用于程序开发过程中通过仅当该程序不正确操作时让expression参量的值为false来识别逻辑错误。在调试完成后,通过定义标识符NDEBUG来修改源文件而关闭断言检测。NDEBUG可以用一个/D命令行选择或一个#define命令来定义。如果用#define定义NDEBUG,该命令必须出现在包括ASSERT.H的语句之前。
assert在expression求值为false(0)时打印一个诊断消息并调用abort终止程序的执行;如果expression为true(非0),则不发生任何动作。该诊断消息包括失败的表达式和该断言失败的源文件名称和行号。
诊断消息的目的依赖调用例程的应用程序的类型。控制台应用程序总是经由stderr接收消息。在单线程或多线程Windows应用程序中,assert调用Windows
MessageBox API函数来建立消息框显示该消息和一个OK按钮,当用户选择OK时,该程序立即终止。
当应用程序与运行库的一个调试版本链接时,assert建立一个有三个按钮:Abort、Retry和Ignore的消息框。如果用户选择Abort,该程序立即终止;如果用户选择Rerty,调用调试器,如果允许及时调试则调试该程序;如果用户选择Ignore,abort继续它的正常执行,建立一个带OK按钮的消息框。注意当存在一个错误条件时选择Ignore会导致不确定的行为。有关更多的信息,参见联机帮助《Visual
C++程序员指南》中的撌褂肅运行库调试支持敗ssert例程可以以C运行库的发行和调试两个版本使用,但仅当定义了DEBUG后计算传给它的表达式。
例子
/* ASSERT.C In this program, the analyzestring function uses
* the assert function to test serveral conditions related to
* string and length. If any of the conditions fails, the program
* prints a message indicating what caused the failure.
*/
#include <stdio.h>
#include <assert.h>
#include <string.h>
void analyzestring( char *string ); /*Prototype */
void main( void )
{
chat test1[]= "abc", *test2 = NULL, test3[]= "";
printf ( "Analyzing string '%s'\n", test1 );
analyzestring( test1 );
printf ( "Analyzing string '%s'\n", test2 );
analyzestring( test2 );
printf ( "Analyzing string '%s'\n", test3 );
analyzestring( test3 );
}
/* Tests a string to see if it is NULL, */
/* empty, or longer than 0 characters */
void analyzestring( char * string )
{
assert( string != NULL );/* Cannot be NULL */
assert( *string != '\0' );/* Cannot be emepy */
assert( strlen( string ) > 2 );/* Length must exceed 2 */
}
输出结果
Analyzing string 'abc'
Analyzing string '(null)'
Assertion failed: string != NULL, file assert.c, line 24
abnormal program termination
参见
abort,raise,signal,ASSERT,ASSERTE,DEBUG
返回顶端
atan, atan2
计算x的反正切值(atan)或y/x的反正切值(atanz)。
double atan(double x);
double atan2(double y,double x);
例程 需要的头 文件兼容性
atan <math.h>ANSI,Win NT, Win 95
atan2 <math.h>ANSI,Win NT, Win 95
对于另外兼容性的信息,参见引言中的兼容性
库
LIBC.LIB 单线程静态库,零售版本
LIBCMT.LIB 多线程静态库,零售版本
MSVCRT.LIB MSVCRT.DLL的输入库,零售版本
返回值
atan返回x的反正切值,atan2返回y/x的反正切值。如果x为0,则atan返回0。
如果atan2的两个参数都为0,该函数返回0。你可以通过使用matheer例程修改错误处理。atan返回一个值,其范围为-π/2到π/2弧度;atan2的返回值范围为-π到π弧度,使用的两个参数的符号确定返回值所在的象限。
参数
x,y
任何数。
说明
atan函数计算x的反正切值。atan2计算y/x的反正切值,atan2对于除原点外的每个点都有定义,甚至在x等于0,y不等0时亦有定义。
例子
/* ATAN.C: This ptogram calculates
* the arctangent of 1 and -1.
*/
#include <math.h>
#include <stdio.h>
#include <errno.h>
void main( void )
{
double x1, x2, y;
printf( "Enter a real number: " );
scanf( "%lf", &x1 );
y = atan( x1 );
printf( "Arctangent of %f: %f\n", x1, y );
printf( "Enter a second real number: " );
scanf( "%lf", &x2 );
y = atan2( x1, x2 );
printf( "Arctangent of %f / %f: %f\n", x1, x2, y );
}
输出结果 Enter a real number: -862.42
Arctangent of -862.420000: -1.569637
Enter a second real number: 78.5149
Arctangent of -862.420000 / 78.514900: -1.480006
参见
acos,asin,cos,marherr,sin,tan
返回顶端
atexit
在退出时处理指定的函数。
int atexit(void( cdecl *func)(void));
例程 需要的头文件 兼容性
atexit <stdlib.h>ANSI,Win NT, Win 95
对于另外兼容性的信息,参见引言中的兼容性
库
LIBC.LIB单线程静态库,零售版本
LIBCMT.LIB多线程静态库,零售版本
MSVCRT.LIBMSVCRT.DLL的输入库,零售版本
返回值
如果成功,atexit返回0;如果出现一个错误则返回一个非0值。
参数
func
被调用的函数。
说明
atexit函数在程序正常终止时传送一个被调用的函数(func)的地址。成功地调用atexit将建立一个以LIFO(后进先出)次序执行的函数寄存器(register),传送给atexit的函数不能有参数。atexit和onexit使用堆保存函数的寄存器,因此,可以被寄存的函数个数仅受限于堆存储器
例子
/* ATEXIT.C: This program pushes four functions onto
* the stack of functions to be executed when atexit
* is called. When the program exits, these programs
* are executed on a "last in, first out" basis.
*/
#include <stdlib.h>
#include <stdio.h>
void fn1( void ), fn( void ), fn3( void ), fn4( void );
voidmain(void)
{
atexit( fn1 );
atexit( fn2 );
atexit( fn3 );
atexit( fn4 );
printf( "This is executed first.\n" );
}
void fn1()
{
printf( "next.\n" );
}
void fn2()
{
printf( "executed " );
}
void fn3()
{
printf( "is " );
}
void fn4()
{
printf( "This " );
}
输出结果
This is executed first.
This is executed next.
参见
abort,exit,onexit
返回顶端
tof,atoi,atoi64,atoll
将字符串转换成双精度(atof)、整数(atoi,atoi64)或者长整数(atol)。
double atof(const char *string);
int ati(const char *string);
int64 atoi64(const char *string);
long atol(const char *string);
例程 需要的头文件 兼容性
atof <math.h>或<stdlib.h>ANSI,Win NT, Win 95
Atoi <stdlib.h>ANSI,Win NT, Win 95
atoi64 <stdlib.h>Win NT, Win 95
Atol <stdlib.h>ANSI,Win NT, Win 95
对于另外兼容性的信息,参见引言中的兼容性
库
LIBC.LIB 单线程静态库,零售版本
LIBCMT.LIB 多线程静态库,零售版本
MSVCRT.LIB MSVCRT.DLL的输入库,零售版本
返回值
每个函数通过转换输入字符串来产生double、int、int64或long值,如果输入不能转换成对应类型的值,返回值为0(对于atoi和atoi64),0L(对atol)或0.0(对atof)。在溢出的情况下返回值是没有意义的。
参数
string
要转换的字符串。
说明
这些函数转换一个字符串为双精度浮点值(atof)、整数值(atoi和atoi64)或长整数(atol),输入字符串是可以转换为指定类型的数值的字符序列,输出的值受到当前场所中LCNUMERIC设置的影响。有关LCNUMERIC的更多信息参见setlocale。atof所能处理的最长字符串尺寸是100个字符。当遇到第一个不能识别作为一个数值部分的字符时,该函数停止读输入的字符串。这个字符可以是字符串结尾的空格字符('\0')。
atof的string参量有如下格式:
[whitespace][sign][digits][.digits][{d|D|e|E}][sign][digits]这里whitespace由空格或制表字符组成,它被忽略;sign是加号(+)或减号(-);digits是一个或多个十进制数字。如果小数点之前没有数字,在小数点之后必须至少有一个数字。十进制数字可以紧跟一个指数,它由一个引志字母(d、D、e或E)及可选的带符号的十进制数字组成。
atoi、atoi64和atol不能识别小数点或指数,这些函数的string有格式:
[whitespace][sign]digits这里whitespace、sign和digits与上面atof的描述完全一样。
通用文本例程映射
TCHAR.H例程 UNCODE&MBCS未定义 MBCS被定义 UNICODE被定义
Ttoi Atoi Atoiwtoi
Ttol atol atol wtol
例子
/* ATOF.C: This program shows how numbers stored
* as strings can be converted to numeric values
* using the atof, atoi, and atol functions.
*/
#include <stdlib.h>
#include <stdio.h>
void main( void )
{
char *s; double x; int i; long l;
s = " -2309.12E-15"; /* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s,
x );
s = "7.8912654773d210";/* Test of atof */
x = atof( s );
printf( "atof test: ASCII string: %s\tfloat: %e\n", s,
x );
s = " -9885 pigs";/* Test of atoi */
i = atoi( s );
printf( "atoi test: ASCII string: %s\t\tinteger: %d\n",
s, i );
s = "98854 dollars";/* Test of atol */
i = atol( s );
printf( "atol test: ASCII string: %s\t\tlong: %ld\n",
s, l );
}
输出结果
atof test: ASCII string:-2309.12E-15 float:-2.309120e-012
atof test: ASCII string: 7.8912654773d210 float:7.891265e+210
atoi test: ASCII string: -9885 pigsinteger:-9885
atol test: ASCII string: 98854 dollars long: 98854
参见
ecvt,fcvt,gcvt,setlocale,strtod,wcstol,strtoul
返回顶端
|