c标准库 英文版
时间:2010-06-13 来源:oychw
C Standard Library
原文地址:http://www.utas.edu.au/infosys/info/documentation/C/CStdLib.html#ctype.h[Last modified : 2006-11-30]
Contents
- <assert.h> : Diagnostics
- <ctype.h> : Character Class Tests
- <errno.h> : Error Codes Reported by (Some) Library Functions
- <float.h> : Implementation-defined Floating-Point Limits
- <limits.h> : Implementation-defined Limits
- <locale.h> : Locale-specific Information
- <math.h> : Mathematical Functions
- <setjmp.h> : Non-local Jumps
- <signal.h> : Signals
- <stdarg.h> : Variable Argument Lists
- <stddef.h> : Definitions of General Use
- <stdio.h> : Input and Output
- <stdlib.h> : Utility functions
- <string.h> : String functions
- <time.h> : Time and Date functions
<assert.h>
void assert(int expression);Macro used for internal error detection. (Ignored if NDEBUG is defined where <assert.h> is included.) If expression equals zero, message printed on stderr and abort called to terminate execution. Source filename and line number in message are from preprocessor macros __FILE__ and __LINE__.[Contents]
<ctype.h>
int isalnum(int c);isalpha(c) or isdigit(c)int isalpha(int c);isupper(c) or islower(c)int iscntrl(int c);is control character. In ASCII, control characters are 0x00 (NUL) to 0x1F (US), and 0x7F (DEL)int isdigit(int c);is decimal digitint isgraph(int c);is printing character other than spaceint islower(int c);is lower-case letterint isprint(int c);is printing character (including space). In ASCII, printing characters are 0x20 (' ') to 0x7E ('~')int ispunct(int c);is printing character other than space, letter, digitint isspace(int c);is space, formfeed, newline, carriage return, tab, vertical tabint isupper(int c);is upper-case letterint isxdigit(int c);is hexadecimal digitint tolower(int c);return lower-case equivalentint toupper(int c);return upper-case equivalent[Contents]
<errno.h>
errnoobject to which certain library functions assign specific positive values on errorEDOMcode used for domain errorsERANGEcode used for range errorsNotes:
- other implementation-defined error values are permitted
- to determine the value (if any) assigned to errno by a library function, a program should assign zero to errno immediately prior to the function call
[Contents]
<float.h>
FLT_RADIXradix of floating-point representationsFLT_ROUNDSfloating-point rounding modeWhere the prefix "FLT" pertains to type float, "DBL" to type double, and "LDBL" to type long double:
FLT_DIGDBL_DIGLDBL_DIGprecision (in decimal digits)FLT_EPSILONDBL_EPSILONLDBL_EPSILONsmallest number x such that 1.0 + x != 1.0FLT_MANT_DIGDBL_MANT_DIGLDBL_MANT_DIGnumber of digits, base FLT_RADIX, in mantissaFLT_MAXDBL_MAXLDBL_MAXmaximum numberFLT_MAX_EXPDBL_MAX_EXPLDBL_MAX_EXPlargest positive integer exponent to which FLT_RADIX can be raised and remain representableFLT_MINDBL_MINLDBL_MINminimum normalised numberFLT_MIN_EXPDBL_MIN_EXPLDBL_MIN_EXPsmallest negative integer exponent to which FLT_RADIX can be raised and remain representable[Contents]
<limits.h>
CHAR_BITnumber of bits in a charCHAR_MAXmaximum value of type charCHAR_MINminimum value of type charSCHAR_MAXmaximum value of type signed charSCHAR_MINminimum value of type signed charUCHAR_MAXmaximum value of type unsigned charSHRT_MAXmaximum value of type shortSHRT_MINminimum value of type shortUSHRT_MAXmaximum value of type unsigned shortINT_MAXmaximum value of type intINT_MINminimum value of type intUINT_MAXmaximum value of type unsigned intLONG_MAXmaximum value of type longLONG_MINminimum value of type longULONG_MAXmaximum value of type unsigned long[Contents]
<locale.h>
struct lconvDescribes formatting of monetary and other numeric values:char* decimal_point;decimal point for non-monetary valueschar* grouping;sizes of digit groups for non-monetary valueschar* thousands_sep;separator for digit groups for non-monetary values (left of "decimal point")char* currency_symbol;currency symbolchar* int_curr_symbol;international currency symbolchar* mon_decimal_point;decimal point for monetary valueschar* mon_grouping;sizes of digit groups for monetary valueschar* mon_thousands_sep;separator for digit groups for monetary values (left of "decimal point")char* negative_sign;negative sign for monetary valueschar* positive_sign;positive sign for monetary valueschar frac_digits;number of digits to be displayed to right of "decimal point" for monetary valueschar int_frac_digits;number of digits to be displayed to right of "decimal point" for international monetary valueschar n_cs_precedes;whether currency symbol precedes (1) or follows (0) negative monetary valueschar n_sep_by_space;whether currency symbol is (1) or is not (0) separated by space from negative monetary valueschar n_sign_posn;format for negative monetary values:0parentheses surround quantity and currency symbol1sign precedes quantity and currency symbol2sign follows quantity and currency symbol3sign immediately precedes currency symbol4sign immediately follows currency symbolchar p_cs_precedes;whether currency symbol precedes (1) or follows (0) positive monetary valueschar p_sep_by_space;whether currency symbol is (1) or is not (0) separated by space from non-negative monetary valueschar p_sign_posn;format for non-negative monetary values, with values as for n_sign_posnImplementations may change field order and include additional fields. Standard C Library functions use only decimal_point.struct lconv* localeconv(void);returns pointer to formatting information for current localechar* setlocale(int category, const char* locale);Sets components of locale according to specified category and locale. Returns string describing new locale or null on error. (Implementations are permitted to define values of category additional to those describe here.)LC_ALLcategory argument for all categoriesLC_NUMERICcategory for numeric formatting informationLC_MONETARYcategory for monetary formatting informationLC_COLLATEcategory for information affecting collating functionsLC_CTYPEcategory for information affecting character class tests functionsLC_TIMEcategory for information affecting time conversions functionsNULLnull pointer constant[Contents]
<math.h>
On domain error, implementation-defined value returned and errno set to EDOM. On range error, errno set to ERANGE and return value is HUGE_VAL with correct sign for overflow, or zero for underflow. Angles are in radians.
HUGE_VALmagnitude returned (with correct sign) on overflow errordouble exp(double x);exponential of xdouble log(double x);natural logarithm of xdouble log10(double x);base-10 logarithm of xdouble pow(double x, double y);x raised to power ydouble sqrt(double x);square root of xdouble ceil(double x);smallest integer not less than xdouble floor(double x);largest integer not greater than xdouble fabs(double x);absolute value of xdouble ldexp(double x, int n);x times 2 to the power ndouble frexp(double x, int* exp);if x non-zero, returns value, with absolute value in interval [1/2, 1), and assigns to *exp integer such that product of return value and 2 raised to the power *exp equals x; if x zero, both return value and *exp are zerodouble modf(double x, double* ip);returns fractional part and assigns to *ip integral part of x, both with same sign as xdouble fmod(double x, double y);if y non-zero, floating-point remainder of x/y, with same sign as x; if y zero, result is implementation-defineddouble sin(double x);sine of xdouble cos(double x);cosine of xdouble tan(double x);tangent of xdouble asin(double x);arc-sine of xdouble acos(double x);arc-cosine of xdouble atan(double x);arc-tangent of xdouble atan2(double y, double x);arc-tangent of y/xdouble sinh(double x);hyperbolic sine of xdouble cosh(double x);hyperbolic cosine of xdouble tanh(double x);hyperbolic tangent of x[Contents]
<setjmp.h>
jmp_buftype of object holding context informationint setjmp(jmp_buf env);Saves context information in env and returns zero. Subsequent call to longjmp with same env returns non-zero.void longjmp(jmp_buf env, int val);Restores context saved by most recent call to setjmp with specified env. Execution resumes as a second return from setjmp, with returned value val if specified value non-zero, or 1 otherwise.[Contents]
<signal.h>
SIGABRTabnormal terminationSIGFPEarithmetic errorSIGILLinvalid executionSIGINT(asynchronous) interactive attentionSIGSEGVillegal storage accessSIGTERM(asynchronous) termination requestSIG_DFLspecifies default signal handlingSIG_ERRsignal return value indicating errorSIG_IGNspecifies that signal should be ignoredvoid (*signal(int sig, void (*handler)(int)))(int);Install handler for subsequent signal sig. If handler is SIG_DFL, implementation-defined default behaviour will be used; if SIG_IGN, signal will be ignored; otherwise function pointed to by handler will be invoked with argument sig. In the last case, handling is restored to default behaviour before handler is called. If handler returns, execution resumes where signal occurred. signal returns the previous handler or SIG_ERR on error. Initial state is implementation-defined. Implementations may may define signals additional to those listed here.int raise(int sig);Sends signal sig. Returns zero on success.[Contents]
<stdarg.h>
va_listtype of object holding context informationvoid va_start(va_list ap, lastarg);Initialisation macro which must be called once before any unnamed argument is accessed. Stores context information in ap. lastarg is the last named parameter of the function.type va_arg(va_list ap, type);Yields value of the type (type) and value of the next unnamed argument.void va_end(va_list ap);Termination macro which must be called once after argument processing and before exit from function.[Contents]
<stddef.h>
NULLNull pointer constant.offsetof(stype, m)Offset (in bytes) of member m from start of structure type stype.ptrdiff_tType for objects declared to store result of subtracting pointers.size_tType for objects declared to store result of sizeof operator.[Contents]
<stdio.h>
BUFSIZSize of buffer used by setbuf.EOFValue used to indicate end-of-stream or to report an error.FILENAME_MAXMaximum length required for array of characters to hold a filename.FOPEN_MAXMaximum number of files which may be open simultaneously.L_tmpnamNumber of characters required for temporary filename generated by tmpnam.NULLNull pointer constant.SEEK_CURValue for origin argument to fseek specifying current file position.SEEK_ENDValue for origin argument to fseek specifying end of file.SEEK_SETValue for origin argument to fseek specifying beginning of file.TMP_MAXMinimum number of unique filenames generated by calls to tmpnam._IOFBFValue for mode argument to setvbuf specifying full buffering._IOLBFValue for mode argument to setvbuf specifying line buffering._IONBFValue for mode argument to setvbuf specifying no buffering.stdinFile pointer for standard input stream. Automatically opened when program execution begins.stdoutFile pointer for standard output stream. Automatically opened when program execution begins.stderrFile pointer for standard error stream. Automatically opened when program execution begins.FILEType of object holding information necessary to control a stream.fpos_tType for objects declared to store file position information.size_tType for objects declared to store result of sizeof operator.FILE* fopen(const char* filename, const char* mode);Opens file named filename and returns a stream, or NULL on failure. mode may be one of the following for text files:"r"text reading"w"text writing"a"text append"r+"text update (reading and writing)"w+"text update, discarding previous content (if any)"a+"text append, reading, and writing at end or one of those strings with b included (after the first character), for binary files.FILE* freopen(const char* filename, const char* mode, FILE* stream);Closes file associated with stream, then opens file filename with specified mode and associates it with stream. Returns stream or NULL on error.int fflush(FILE* stream);Flushes stream stream and returns zero on success or EOF on error. Effect undefined for input stream. fflush(NULL) flushes all output streams.int fclose(FILE* stream);Closes stream stream (after flushing, if output stream). Returns EOF on error, zero otherwise.int remove(const char* filename);Removes specified file. Returns non-zero on failure.int rename(const char* oldname, const char* newname);Changes name of file oldname to newname. Returns non-zero on failure.FILE* tmpfile();Creates temporary file (mode "wb+") which will be removed when closed or on normal program termination. Returns stream or NULL on failure.char* tmpnam(char s[L_tmpnam]);Assigns to s (if s non-null) and returns unique name for a temporary file. Unique name is returned for each of the first TMP_MAX invocations.int setvbuf(FILE* stream, char* buf, int mode, size_t size);Controls buffering for stream stream. mode is _IOFBF for full buffering, _IOLBF for line buffering, _IONBF for no buffering. Non-null buf specifies buffer of size size to be used; otherwise, a buffer is allocated. Returns non-zero on error. Call must be before any other operation on stream.void setbuf(FILE* stream, char* buf);Controls buffering for stream stream. For null buf, turns off buffering, otherwise equivalent to (void)setvbuf(stream, buf, _IOFBF, BUFSIZ).int fprintf(FILE* stream, const char* format, ...);Converts (according to format format) and writes output to stream stream. Number of characters written, or negative value on error, is returned. Conversion specifications consist of:- %
- (optional) flag:-left adjust+always signspacespace if no sign0zero pad#Alternate form: for conversion character o, first digit will be zero, for [xX], prefix 0x or 0X to non-zero value, for [eEfgG], always decimal point, for [gG] trailing zeros not removed.
- (optional) minimum width: if specified as *, value taken from next argument (which must be int).
- (optional) . (separating width from precision):
- (optional) precision: for conversion character s, maximum characters to be printed from the string, for [eEf], digits after decimal point, for [gG], significant digits, for an integer, minimum number of digits to be printed. If specified as *, value taken from next argument (which must be int).
- (optional) length modifier:hshort or unsigned shortllong or unsigned longLlong double
- conversion character:d,iint argument, printed in signed decimal notationoint argument, printed in unsigned octal notationx,Xint argument, printed in unsigned hexadecimal notationuint argument, printed in unsigned decimal notationcint argument, printed as single characterschar* argumentfdouble argument, printed with format [-]mmm.ddde,Edouble argument, printed with format [-]m.dddddd(e|E)(+|-)xxg,Gdouble argumentpvoid* argument, printed as pointernint* argument : the number of characters written to this point is written into argument%no argument; prints %
- blanks and tabs, which are ignored
- ordinary characters, which are expected to match next non-white-space of input
- conversion specifications, consisting of:
- %
- (optional) assignment suppression character "*"
- (optional) maximum field width
- (optional) target width indicator:hargument is pointer to short rather than intlargument is pointer to long rather than int, or double rather than floatLargument is pointer to long double rather than float
- conversion character: ddecimal integer; int* parameter requirediinteger; int* parameter required; decimal, octal or hexooctal integer; int* parameter requireduunsigned decimal integer; unsigned int* parameter requiredxhexadecimal integer; int* parameter requiredccharacters; char* parameter required; white-space is not skipped, and NUL-termination is not performedsstring of non-white-space; char* parameter required; string is NUL-terminatede,f,gfloating-point number; float* parameter requiredppointer value; void* parameter requirednchars read so far; int* parameter required[...]longest non-empty string from specified set; char* parameter required; string is NUL-terminated[^...]longest non-empty string not from specified set; char* parameter required; string is NUL-terminated%literal %; no assignment
fprintf(stderr, "%s: %s\n", (s != NULL ? s : ""), strerror(errno))
[Contents]
<stdlib.h>
EXIT_FAILUREValue for status argument to exit indicating failure.EXIT_SUCCESSValue for status argument to exit indicating success.RAND_MAXMaximum value returned by rand().NULLNull pointer constant.div_tReturn type of div(). Structure having members:int quot; quotientint rem; remainderldiv_tReturn type of ldiv(). Structure having members:long quot; quotientlong rem; remaindersize_tType for objects declared to store result of sizeof operator.int abs(int n);long labs(long n);Returns absolute value of n.div_t div(int num, int denom);ldiv_t ldiv(long num, long denom);Returns quotient and remainder of num/denom.double atof(const char* s);Equivalent to strtod(s, (char**)NULL) except that errno is not necessarily set on conversion error.int atoi(const char* s);Equivalent to (int)strtol(s, (char**)NULL, 10) except that errno is not necessarily set on conversion error.long atol(const char* s);Equivalent to strtol(s, (char**)NULL, 10) except that errno is not necessarily set on conversion error.double strtod(const char* s, char** endp);Converts initial characters (ignoring leading white space) of s to type double. If endp non-null, stores pointer to unconverted suffix in *endp. On overflow, sets errno to ERANGE and returns HUGE_VAL with the appropriate sign; on underflow, sets errno to ERANGE and returns zero; otherwise returns converted value.long strtol(const char* s, char** endp, int base);Converts initial characters (ignoring leading white space) of s to type long. If endp non-nu ll, stores pointer to unconverted suffix in *endp. If base between 2 and 36, that base used for conversion; if zero, leading (after any sign) 0X or 0x implies hexadecimal, leading 0 (after any sign) implies octal, otherwise decimal assumed. Leading 0X or 0x permitted for base hexadecimal. On overflow, sets errno to ERANGE and returns LONG_MAX or LONG_MIN (as appropriate for sign); otherwise returns converted value.unsigned long strtoul(const char* s, char** endp, int base);As for strtol except result is unsigned long and value on overflow is ULONG_MAX.void* calloc(size_t nobj, size_t size);Returns pointer to zero-initialised newly-allocated space for an array of nobj objects each of size size, or NULL on error.void* malloc(size_t size);Returns pointer to uninitialised newly-allocated space for an object of size size, or NULL on error.void* realloc(void* p, size_t size);Returns pointer to newly-allocated space for an object of size size, initialised, to minimum of old and new sizes, to existing contents of p (if non-null), or NULL on error. On success, old object deallocated, otherwise unchanged.void free(void* p);If p non-null, deallocates space to which it points.void abort();Terminates program abnormally, by calling raise(SIGABRT).void exit(int status);Terminates program normally. Functions installed using atexit are called (in reverse order to that in which installed), open files are flushed, open streams are closed and control is returned to environment. status is returned to environment in implementation-dependent manner. Zero or EXIT_SUCCESS indicates successful termination and EXIT_FAILURE indicates unsuccessful termination. Implementations may define other values.int atexit(void (*fcm)(void));Registers fcn to be called when program terminates normally (or when main returns). Returns non-zero on failure.int system(const char* s);If s is not NULL, passes s to environment for execution, and returns status reported by command processor; if s is NULL, non-zero returned if environment has a command processor.char* getenv(const char* name);Returns string associated with name name from implementation's environment, or NULL if no such string exists.void* bsearch(const void* key, const void* base, size_t n, size_t size, int (*cmp)(const void* keyval, const void* datum));Searches ordered array base (of n objects each of size size) for item matching key according to comparison function cmp. cmp must return negative value if first argument is less than second, zero if equal and positive if greater. Items of base are assumed to be in ascending order (according to cmp). Returns a pointer to an item matching key, or NULL if none found.void qsort(void* base, size_t n, size_t size, int (*cmp)(const void*, const void*));Arranges into ascending order array base (of n objects each of size size) according to comparison function cmp. cmp must return negative value if first argument is less than second, zero if equal and positive if greater.int rand(void);Returns pseudo-random number in range 0 to RAND_MAX.void srand(unsigned int seed);Uses seed as seed for new sequence of pseudo-random numbers. Initial seed is 1.[Contents]
<string.h>
NULLNull pointer constant.size_tType for objects declared to store result of sizeof operator.char* strcpy(char* s, const char* ct);Copies ct to s including terminating NUL and returns s.char* strncpy(char* s, const char* ct, size_t n);Copies at most n characters of ct to s. Pads with NUL characters if ct is of length less than n. Note that this may leave s without NUL-termination. Return s.char* strcat(char* s, const char* ct);Concatenate ct to s and return s.char* strncat(char* s, const char* ct, size_t n);Concatenate at most n characters of ct to s. NUL-terminates s and return it.int strcmp(const char* cs, const char* ct);Compares cs with ct, returning negative value if cs<ct, zero if cs==ct, positive value if cs>ct.int strncmp(const char* cs, const char* ct, size_t n);Compares at most (the first) n characters of cs and ct, returning negative value if cs<ct, zero if cs==ct, positive value if cs>ct.int strcoll(const char* cs, const char* ct);Compares cs with ct according to locale, returning negative value if cs<ct, zero if cs==ct, positive value if cs>ct.char* strchr(const char* cs, int c);Returns pointer to first occurrence of c in cs, or NULL if not found.char* strrchr(const char* cs, int c);Returns pointer to last occurrence of c in cs, or NULL if not found.size_t strspn(const char* cs, const char* ct);Returns length of prefix of cs which consists of characters which are in ct.size_t strcspn(const char* cs, const char* ct);Returns length of prefix of cs which consists of characters which are not in ct.char* strpbrk(const char* cs, const char* ct);Returns pointer to first occurrence in cs of any character of ct, or NULL if none is found.char* strstr(const char* cs, const char* ct);Returns pointer to first occurrence of ct within cs, or NULL if none is found.size_t strlen(const char* cs);Returns length of cs.char* strerror(int n);Returns pointer to implementation-defined message string corresponding with error n.char* strtok(char* s, const char* t);Searches s for next token delimited by any character from ct. Non-NULL s indicates the first call of a sequence. If a token is found, it is NUL-terminated and returned, otherwise NULL is returned. ct need not be identical for each call in a sequence.size_t strxfrm(char* s, const char* ct, size_t n);Stores in s no more than n characters (including terminating NUL) of a string produced from ct according to a locale-specific transformation. Returns length of entire transformed string.void* memcpy(void* s, const void* ct, size_t n);Copies n characters from ct to s and returns s. s may be corrupted if objects overlap.void* memmove(void* s, const void* ct, size_t n);Copies n characters from ct to s and returns s. s will not be corrupted if objects overlap.int memcmp(const void* cs, const void* ct, size_t n);Compares at most (the first) n characters of cs and ct, returning negative value if cs<ct, zero if cs==ct, positive value if cs>ct.void* memchr(const void* cs, int c, size_t n);Returns pointer to first occurrence of c in first n characters of cs, or NULL if not found.void* memset(void* s, int c, size_t n);Replaces each of the first n characters of s by c and returns s.[Contents]
<time.h>
CLOCKS_PER_SECThe number of clock_t units per second.NULLNull pointer constant.clock_tAn arithmetic type elapsed processor representing time.time_tAn arithmetic type representing calendar time.struct tmRepresents the components of calendar time: int tm_sec;seconds after the minuteint tm_min;minutes after the hourint tm_hour;hours since midnightint tm_mday;day of the monthint tm_mon;months since Januaryint tm_year;years since 1900int tm_wday;days since Sundayint tm_yday;days since January 1int tm_isdst;Daylight Saving Time flag : is positive if DST is in effect, zero if not in effect, negative if information not known.Implementations may change field order and include additional fields.clock_t clock(void);Returns elapsed processor time used by program or -1 if not available.time_t time(time_t* tp);Returns current calendar time or -1 if not available. If tp is non-NULL, return value is also assigned to *tp.double difftime(time_t time2, time_t time1);Returns the difference in seconds between time2 and time1.time_t mktime(struct tm* tp);If necessary, adjusts fields of *tp to fall withing normal ranges. Returns the corresponding calendar time, or -1 if it cannot be represented.char* asctime(const struct tm* tp);Returns the given time as a string of the form:Sun Jan 3 13:08:42 1988\n\0char* ctime(const time_t* tp);Returns string equivalent to calendar time tp converted to local time. Equivalent to:
asctime(localtime(tp))struct tm* gmtime(const time_t* tp);Returns calendar time *tp converted to Coordinated Universal Time, or NULL if not available.struct tm* localtime(const time_t* tp);Returns calendar time *tp converted into local time.size_t strftime(char* s, size_t smax, const char* fmt, const struct tm* tp);Formats *tp into s according to fmt. Places no more than smax characters into s, and returns number of characters produced (excluding terminating NUL), or 0 if greater than smax. Formatting conversions (%c) are:Aname of weekdayaabbreviated name of weekdayBname of monthbabbreviated name of monthclocal date and time representationdday of month [01-31]Hhour (24-hour clock) [00-23]Ihour (12-hour clock) [01-12]jday of year [001-366]Mminute [00-59]mmonth [01-12]plocal equivalent of "AM" or "PM"Ssecond [00-61]Uweek number of year (Sunday as 1st day of week) [00-53]Wweek number of year (Monday as 1st day of week) [00-53]wweekday (Sunday as 0) [0-6]Xlocal time representationxlocal date representationYyear with centuryyyear without century [00-99]Zname (if any) of time zone%%
Local time may differ from calendar time because of time zone.
相关阅读 更多 +