📄 appb.html
字号:
<td><tt>char *strncat(s,ct,n)</tt></td><td>concatenate at most <tt>n</tt> characters of string <tt>ct</tt> to string <tt>s</tt>, terminate <tt>s</tt> with <tt>'\0'</tt>; return <tt>s</tt>.</td><tr><td><tt>int strcmp(cs,ct)</tt></td><td>compare string <tt>cs</tt> to string <tt>ct</tt>, return <0 if <tt>cs<ct</tt>, 0 if <tt>cs==ct</tt>, or >0 if <tt>cs>ct</tt>.</td><tr><td><tt>int strncmp(cs,ct,n)</tt></td><td>compare at most <tt>n</tt> characters of string <tt>cs</tt> to string <tt>ct</tt>; return <0 if <tt>cs<ct</tt>, 0 if <tt>cs==ct</tt>, or >0 if <tt>cs>ct</tt>.</td><tr><td><tt>char *strchr(cs,c)</tt></td><td>return pointer to first occurrence of <tt>c</tt> in <tt>cs</tt> or <tt>NULL</tt> if not present.</td><tr><td><tt>char *strrchr(cs,c)</tt></td><td>return pointer to last occurrence of <tt>c</tt> in <tt>cs</tt> or <tt>NULL</tt> if not present.</td><tr><td><tt>size_t strspn(cs,ct)</tt></td><td>return length of prefix of <tt>cs</tt> consisting of characters in <tt>ct</tt>.</td><tr><td><tt>size_t strcspn(cs,ct)</tt></td><td>return length of prefix of <tt>cs</tt> consisting of characters <em>not</em> in <tt>ct</tt>.</td><tr><td><tt>char *strpbrk(cs,ct)</tt></td><td>return pointer to first occurrence in string <tt>cs</tt> of any character string <tt>ct</tt>, or <tt>NULL</tt> if not present.</td><tr><td><tt>char *strstr(cs,ct)</tt></td><td>return pointer to first occurrence of string <tt>ct</tt> in <tt>cs</tt>, or <tt>NULL</tt> if not present.</td><tr><td><tt>size_t strlen(cs)</tt></td><td>return length of <tt>cs</tt>.</td><tr><td><tt>char *strerror(n)</tt></td><td>return pointer to implementation-defined string corresponding to error <tt>n</tt>.</td><tr><td><tt>char *strtok(s,ct)</tt></td><td><tt>strtok</tt> searches <tt>s</tt> for tokens delimited by characters from <tt>ct</tt>; see below.</td></table><p>A sequence of calls of <tt>strtok(s,ct)</tt> splits <tt>s</tt> into tokens, eachdelimited by a character from <tt>ct</tt>. The first call in a sequence has anon-<tt>NULL s</tt>, it finds the first token in <tt>s</tt> consisting ofcharacters not in <tt>ct</tt>; it terminates that by overwriting the nextcharacter of <tt>s</tt> with <tt>'\0'</tt> and returns a pointer to the token. Eachsubsequent call, indicated by a <tt>NULL</tt> value of <tt>s</tt>, returns the nextsuch token, searching from just past the end of the previous one. <tt>strtok</tt>returns <tt>NULL</tt> when no further token is found. The string <tt>ct</tt> may bedifferent on each call.<p>The <tt>mem...</tt> functions are meant for manipulating objects as characterarrays; the intent is an interface to efficient routines. In the followingtable, <tt>s</tt> and <tt>t</tt> are of type <tt>void *</tt>; <tt>cs</tt> and <tt>ct</tt> areof type <tt>const void *</tt>; <tt>n</tt> is of type <tt>size_t</tt>; and <tt>c</tt> is an<tt>int</tt> converted to an <tt>unsigned char</tt>.<p align="center"><table border=0><td><tt>void *memcpy(s,ct,n)</tt></td><td>copy <tt>n</tt> characters from <tt>ct</tt> to <tt>s</tt>, and return <tt>s</tt>.</td><tr><td><tt>void *memmove(s,ct,n)</tt></td><td>same as <tt>memcpy</tt> except that it works even if the objects overlap.</td><tr><td><tt>int memcmp(cs,ct,n)</tt></td><td>compare the first <tt>n</tt> characters of <tt>cs</tt> with <tt>ct</tt>; return as with <tt>strcmp</tt>.</td><tr><td><tt>void *memchr(cs,c,n)</tt></td><td>return pointer to first occurrence of character <tt>c</tt> in <tt>cs</tt>, or <tt>NULL</tt> if not present among the first <tt>n</tt> characters.</td><tr><td><tt>void *memset(s,c,n)</tt></td><td>place character <tt>c</tt> into first <tt>n</tt> characters of <tt>s</tt>, return <tt>s</tt>.</td></table><h2><a name="sb.4">B.4 Mathematical Functions: <math.h></a></h2>The header <tt><math.h></tt> declares mathematical functions and macros.<p>The macros <tt>EDOM</tt> and <tt>ERANGE</tt> (found in<tt><errno.h></tt>) are non-zero integral constants that are used tosignal domain and range errors for the functions; <tt>HUGE_VAL</tt> is apositive <tt>double</tt> value. A <em>domain error</em> occurs if an argumentis outside the domain over which the function is defined. On a domain error,<tt>errno</tt> is set to <tt>EDOM</tt>; the return value isimplementation-defined. A <em>range error</em> occurs if the result of thefunction cannot be represented as a <tt>double</tt>. If the result overflows,the function returns <tt>HUGE_VAL</tt> with the right sign, and<tt>errno</tt> is set to <tt>ERANGE</tt>. If the result underflows, thefunction returns zero; whether <tt>errno</tt> is set to <tt>ERANGE</tt> isimplementation-defined.<p>In the following table, <tt>x</tt> and <tt>y</tt> are of type<tt>double</tt>, <tt>n</tt> is an <tt>int</tt>, and all functions return<tt>double</tt>. Angles for trigonometric functions are expressed in radians.<p align="center"><table><td><tt>sin(x)</tt> </td><td>sine of <em>x</em></td><tr><td><tt>cos(x)</tt> </td><td>cosine of <em>x</em></td><tr><td><tt>tan(x)</tt> </td><td>tangent of <em>x</em></td><tr><td><tt>asin(x)</tt> </td><td>sin<sup>-1</sup>(x) in range [-pi/2,pi/2], x in [-1,1].</td><tr><td><tt>acos(x)</tt> </td><td>cos<sup>-1</sup>(x) in range [0,pi], x in [-1,1].</td><tr><td><tt>atan(x)</tt> </td><td>tan<sup>-1</sup>(x) in range [-pi/2,pi/2].</td><tr><td><tt>atan2(y,x)</tt></td><td>tan<sup>-1</sup>(y/x) in range [-pi,pi].</td><tr><td><tt>sinh(x)</tt> </td><td>hyperbolic sine of <em>x</em></td><tr><td><tt>cosh(x)</tt> </td><td>hyperbolic cosine of <em>x</em></td><tr><td><tt>tanh(x)</tt> </td><td>hyperbolic tangent of <em>x</em></td><tr><td><tt>exp(x)</tt> </td><td>exponential function <em>e<sup>x</sup></em></td><tr><td><tt>log(x)</tt> </td><td>natural logarithm ln(x), <em>x</em>>0.</td><tr><td><tt>log10(x)</tt> </td><td>base 10 logarithm log<sub>10</sub>(x), <em>x</em>>0.</td><tr><td><tt>pow(x,y)</tt> </td><td><em>x<sup>y</sup></em>. A domain error occurs if <em>x=0</em> and <em>y<=0</em>, or if <em>x<0</em> and <em>y</em> is not an integer.</td><tr><td><tt>sqrt(x)</tt> </td><td>sqare root of x, x>=0.</td><tr><td><tt>ceil(x)</tt> </td><td>smallest integer not less than <tt>x</tt>, as a <tt>double</tt>.</td><tr><td><tt>floor(x)</tt> </td><td>largest integer not greater than <tt>x</tt>, as a <tt>double</tt>.</td><tr><td><tt>fabs(x)</tt> </td><td>absolute value |x|</td><tr><td><tt>ldexp(x,n)</tt></td><td>x*2<sup>n</sup></td><tr><td><tt>frexp(x, int *ip)</tt></td><td>splits <em>x</em> into a normalized fraction in the interval [1/2,1) which is returned, and a power of 2, which is stored in <tt>*exp</tt>. If <em>x</em> is zero, both parts of the result are zero.</td><tr><td><tt>modf(x, double *ip)</tt></td><td>splits <em>x</em> into integral and fractional parts, each with the same sign as <em>x</em>. It stores the integral part in <tt>*ip</tt>, and returns the fractional part.</td><tr><td><tt>fmod(x,y)</tt></td><td>floating-point remainder of <em>x/y</em>, with the same sign as <em>x</em>. If <em>y</em> is zero, the result is implementation-defined.</table><h2><a name="sb.5">B.5 Utility Functions: <stdlib.h></a></h2>The header <tt><stdlib.h></tt> declares functions for number conversion,storage allocation, and similar tasks.<dl><td><tt>double atof(const char *s)</tt><dd><tt>atof</tt> converts <tt>s</tt> to <tt>double</tt>; it is equivalent to<tt>strtod(s, (char**)NULL)</tt>.<p><dt><tt>int atoi(const char *s)</tt><dd>converts <tt>s</tt> to <tt>int</tt>; it is equivalent to<tt>(int)strtol(s, (char**)NULL, 10)</tt>.<p><dt><tt>long atol(const char *s)</tt><dd>converts <tt>s</tt> to <tt>long</tt>; it is equivalent to<tt>strtol(s, (char**)NULL, 10)</tt>.<p><dt><tt>double strtod(const char *s, char **endp)</tt><dd><tt>strtod</tt> converts the prefix of <tt>s</tt> to <tt>double</tt>, ignoring leadingwhite space; it stores a pointer to any unconverted suffix in <tt>*endp</tt>unless <tt>endp</tt> is <tt>NULL</tt>. If the answer would overflow, <tt>HUGE_VAL</tt>is returned with the proper sign; if the answer would underflow, zero isreturned. In either case <tt>errno</tt> is set to <tt>ERANGE</tt>.<p><dt><tt>long strtol(const char *s, char **endp, int base)</tt><dd><tt>strtol</tt> converts the prefix of <tt>s</tt> to <tt>long</tt>, ignoring leadingwhite space; it stores a pointer to any unconverted suffix in <tt>*endp</tt>unless <tt>endp</tt> is <tt>NULL</tt>. If <tt>base</tt> is between 2 and 36, conversionis done assuming that the input is written in that base. If <tt>base</tt> iszero, the base is 8, 10, or 16; leading 0 implies octal and leading <tt>0x</tt>or <tt>0X</tt> hexadecimal. Letters in either case represent digits from 10 to<tt>base-1</tt>; a leading <tt>0x</tt> or <tt>0X</tt> is permitted in base 16. If theanswer would overflow, <tt>LONG_MAX</tt> or <tt>LONG_MIN</tt> is returned,depending on the sign of the result, and <tt>errno</tt> is set to <tt>ERANGE</tt>.<p><dt><tt>unsigned long strtoul(const char *s, char **endp, int base)</tt><dd><tt>strtoul</tt> is the same as <tt>strtol</tt> except that the result is<tt>unsigned long</tt> and the error value is <tt>ULONG_MAX</tt>.<p><dt><tt>int rand(void)</tt><dd><tt>rand</tt> returns a pseudo-random integer in the range 0 to <tt>RAND_MAX</tt>, which is at least 32767.<p><dt><tt>void srand(unsigned int seed)</tt><dd><tt>srand</tt> uses <tt>seed</tt> as the seed for a new sequence of pseudo-randomnumbers. The initial seed is 1.<p><dt><tt>void *calloc(size_t nobj, size_t size)</tt><dd><tt>calloc</tt> returns a pointer to space for an array of <tt>nobj</tt> objects, each of size <tt>size</tt>, or <tt>NULL</tt> if the request cannot be satisfied. The space is initialized to zero bytes.<p><dt><tt>void *malloc(size_t size)</tt><dd><tt>malloc</tt> returns a pointer to space for an object of size <tt>size</tt>, or<tt>NULL</tt> if the request cannot be satisfied. The space is uninitialized.<p><dt><tt>void *realloc(void *p, size_t size)</tt><dd><tt>realloc</tt> changes the size of the object pointed to by <tt>p</tt> to <tt>size</tt>. The contents will be unchanged up to the minimum of the old and new sizes. If the new size is larger, the new space is uninitialized. <tt>realloc</tt> returns a pointer to the new space, or <tt>NULL</tt> if the request cannot be satisfied, in which case <tt>*p</tt> is unchanged.<p><dt><tt>void free(void *p)</tt><dd><tt>free</tt> deallocates the space pointed to by <tt>p</tt>; it does nothing if<tt>p</tt> is <tt>NULL</tt>. <tt>p</tt> must be a pointer to space previously allocatedby <tt>calloc</tt>, <tt>malloc</tt>, or <tt>realloc</tt>.<p><dt><tt>void abort(void)</tt><dd><tt>abort</tt> causes the program to terminate abnormally, as if by <tt>raise(SIGABRT)</tt>.<p><dt><tt>void exit(int status)</tt><dd><tt>exit</tt> causes normal program termination. <tt>atexit</tt> functions are called in reverse order of registration, open files are flushed, open streams are closed, and control is returned to the environment. How <tt>status</tt> is returned to the environment is implementation-dependent, but zero is taken as successful termination. The values <tt>EXIT_SUCCESS</tt> and <tt>EXIT_FAILURE</tt> may also be used.<p><dt><tt>int atexit(void (*fcn)(void))</tt><dd><tt>atexit</tt> registers the function <tt>fcn</tt> to be called when the program terminates normally; it returns non-zero if the registration cannot be made.<p><dt><tt>int system(const char *s)</tt><dd><tt>system</tt> passes the string <tt>s</tt> to the environment for execution. If <tt>s</tt> is <tt>NULL</tt>, <tt>system</tt> returns non-zero if there is a command processor. If <tt>s</tt> is not <tt>NULL</tt>, the return value is implementation-dependent.<p><dt><tt>char *getenv(const char *name)</tt><dd><tt>getenv</tt> returns the environment string associated with <tt>name</tt>, or <tt>NULL</tt> if no string exists. Details are implementation-dependent.<dt><pre>void *bsearch(const void *key, const void *base, size_t n, size_t size, int (*cmp)(const void *keyval, const void *datum))</pre><dd><tt>bsearch</tt> searches <tt>base[0]...base[n-1]</tt> for an item that matches <tt>*key</tt>. The function <tt>cmp</tt> must return negative if its first argument (the search key) is less than its second (a table entry), zero if equal, and positive if greater. Items in the array <tt>base</tt> must be in ascending order. <tt>bsearch</tt> returns a pointer to a matching item, or <tt>NULL</tt> if none exists.<dt><pre>void qsort(void *base, size_t n, size_t size, int (*cmp)(const void *, const void *))</pre><dd><tt>qsort</tt> sorts into ascending order an array <tt>base[0]...base[n-1]</tt> of objects of size <tt>size</tt>. The comparison function <tt>cmp</tt> is as in <tt>bsearch</tt>.<p><dt><tt>int abs(int n)</tt><dd><tt>abs</tt> returns the absolute value of its <tt>int</tt> argument.<p><dt><tt>long labs(long n)</tt><dd><tt>labs</tt> returns the absolute value of its <tt>long</tt> argument.<p><dt><tt>div_t div(int num, int denom)</tt><dd><tt>div</tt> computes the quotient and remainder of <tt>num/denom</tt>. The results are stored in the <tt>int</tt> members <tt>quot</tt> and <tt>rem</tt> of a structure of type <tt>div_t</tt>.<p><dt><tt>ldiv_t ldiv(long num, long denom)</tt><dd><tt>ldiv</tt> computes the quotient and remainder of <tt>num/denom</tt>. The results are stored in the <tt>long</tt> members <tt>quot</tt> and <tt>rem</tt> of a structure of type <tt>ldiv_t</tt>.</dl><h2><a name="sb.6">B.6 Diagnostics: <assert.h></a></h2>The <tt>assert</tt> macro is used to add diagnostics to programs:<p> <tt>void assert(int <em>expression</em>)</tt><p>If <em>expression</em> is zero when<p> <tt>assert(<em>expression</em>)</tt><p>is executed, the <tt>assert</tt> macro will print on <tt>stderr</tt> a message,such as<p> <tt>Assertion failed:</tt> <em>expression</em>, <tt>file</tt> <em>filename</em>, <tt>line</tt> <em>nnn</em><p>It then calls <tt>abort</tt> to terminate execution. The source filename andline number come from the preprocessor macros <tt>__FILE__</tt> and<tt>__LINE__</tt>.<p>If <tt>NDEBUG</tt> is defined at the time <tt><assert.h></tt> is included,the assert macro is ignored.<h2><a name="sb.7">B.7 Variable Argument Lists: <stdarg.h></a></h2>The header <tt><stdarg.h></tt> provides facilities for stepping through a list
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -