⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stdother_details.html

📁 ssd5 数据结构的课件
💻 HTML
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <meta name="generator" content="HTML Tidy for Linux/x86 (vers 1st October 2002), see www.w3.org">    <title>Other standard C functions</title>  </head>  <body bgcolor="#ffffff">    <table width="100%" bgcolor="#eeeeff">      <tr>        <td><a href="index.html">cppreference.com</a> -&gt; <a href="stdother.html">Other standard C        functions</a> -&gt; Details</td>      </tr>    </table>    <h1>Other standard C functions</h1>    <hr>    <h2><a name="abort">abort</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdlib.h&gt;  void abort( void );</pre>        </td>      </tr>    </table>    <p>The function abort() terminates the current program. Depending on the implementation, the return value    can indicate failure.</p>    <i>Related topics:</i><br>     <strong><a href="#exit">exit()</a> and <a href="#atexit">atexit()</a>.</strong>     <hr>    <h2><a name="assert">assert</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;assert.h&gt;  void assert( int exp );</pre>        </td>      </tr>    </table>    <p>The assert() macro is used to test for errors. If <i>exp</i> evaluates to zero, assert() writes    information to STDERR and exits the program. If the macro NDEBUG is defined, the assert() macros will be    ignored.</p>    <i>Related topics:</i><br>     <strong><a href="#abort">abort()</a></strong>     <hr>    <h2><a name="atexit">atexit</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdlib.h&gt;  int atexit( void (*func)(void) );</pre>        </td>      </tr>    </table>    <p>The function atexit() causes the function pointed to by <i>func</i> to be called when the program    terminates. You can make multiple calls to atexit() (at least 32, depending on your compiler) and those functions will be called in    reverse order of their establishment. The return value of atexit() is zero upon success, and nonzero on    failure.</p>    <i>Related topics:</i><br>     <strong><a href="#exit">exit()</a> and <a href="#abort">abort()</a>.</strong>     <hr>    <h2><a name="bsearch">bsearch</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdlib.h&gt;  void *bsearch( const void *key, const void *buf, size_t num, size_t size, int (*compare)(const void *, const void *) );</pre>        </td>      </tr>    </table>    <p>The bsearch() function searches <i>buf[0]</i> to <i>buf[num-1]</i> for an item that matches    <i>key</i>, using a binary search. The function <i>compare</i> should return negative if its first    argument is less than its second, zero if equal, and positive if greater. The items in the array    <i>buf</i> should be in ascending order. The return value of bsearch() is a pointer to the matching item,    or NULL if none is found.</p>    <i>Related topics:</i><br>     <strong><a href="#qsort">qsort()</a>.</strong>     <hr>    <h2><a name="exit">exit</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdlib.h&gt;  void exit( int exit_code );</pre>        </td>      </tr>    </table>    <p>The exit() function stops the program. <i>exit_code</i> is passed on to be the return value of the    program, where usually zero indicates success and non-zero indicates an error.</p>    <i>Related topics:</i><br>     <strong><a href="#atexit">atexit()</a> and <a href="#abort">abort()</a>.</strong>     <hr>    <h2><a name="getenv">getenv</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdlib.h&gt;  char *getenv( const char *name );</pre>        </td>      </tr>    </table>    <p>The function getenv() returns environmental information associated with <i>name</i>, and is very    implementation dependent. NULL is returned if no information about <i>name</i> is available.</p>    <i>Related topics:</i><br>     <strong><a href="#system">system()</a>.</strong>     <hr>    <h2><a name="longjmp">longjmp</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;setjmp.h&gt;  void longjmp( jmp_buf envbuf, int status );</pre>        </td>      </tr>    </table>    <p>The function longjmp() causes the program to start executing code at the point of the last call to <a    href="#setjmp">setjmp()</a>. <i>envbuf</i> is usually set through a call to <a href=    "#setjmp">setjmp()</a>. <i>status</i> becomes the return value of <a href="#setjmp">setjmp()</a> and can    be used to figure out where longjmp() came from. <i>status</i> should not be set to zero.</p>    <i>Related topics:</i><br>     <strong><a href="#setjmp">setjmp()</a>.</strong>     <hr>    <h2><a name="qsort">qsort</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdlib.h&gt;  void qsort( void *buf, size_t num, size_t size, int (*compare)(const void *, const void *) );</pre>        </td>      </tr>    </table>    <p>The qsort() function sorts <i>buf</i> (which contains <i>num</i> items, each of size <i>size</i>)    using Quicksort. The <i>compare</i> function is used to compare the items in <i>buf</i>. <i>compare</i>    should return negative if the first argument is less than the second, zero if they are equal, and    positive if the first argument is greater than the second. qsort() sorts <i>buf</i> in ascending    order.</p>    <i>Related topics:</i><br>     <strong><a href="#bsearch">bsearch()</a>.</strong>     <hr>    <h2><a name="raise">raise</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;signal.h&gt;  int raise( int signal );</pre>        </td>      </tr>    </table>    <p>The raise() function sends the specified <i>signal</i> to the program. Some signals:</p>    <table bgcolor="#eeeeff">      <tr>        <td><strong>Signal</strong></td>        <td><strong>Meaning</strong></td>      </tr>      <tr>        <td>SIGABRT</td>        <td>Termination error</td>      </tr>      <tr>        <td>SIGFPE</td>        <td>Floating pointer error</td>      </tr>      <tr>        <td>SIGILL</td>        <td>Bad instruction</td>      </tr>      <tr>        <td>SIGINT</td>        <td>User presed CTRL-C</td>      </tr>      <tr>        <td>SIGSEGV</td>        <td>Illegal memory access</td>      </tr>      <tr>        <td>SIGTERM</td>        <td>Terminate program</td>      </tr>    </table>    <p>The return value is zero upon success, nonzero on failure.</p>    <i>Related topics:</i><br>     <strong><a href="#signal">signal()</a></strong>     <hr>    <h2><a name="rand">rand</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdlib.h&gt;  int rand( void );</pre>        </td>      </tr>    </table>    <p>The function rand() returns a pseudorandom integer between zero and <strong>RAND_MAX</strong>. An    example:</p><pre>    srand( time(NULL) );    for( i = 0; i &lt; 10; i++ )      printf( "Random number #%d: %d\n", i, rand() );</pre>    <i>Related topics:</i><br>     <strong><a href="#srand">srand()</a></strong>     <hr>    <h2><a name="setjmp">setjmp</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;setjmp.h&gt;  int setjmp( jmp_buf envbuf );</pre>        </td>      </tr>    </table>    <p>The setjmp() function saves the system stack in <i>envbuf</i> for use by a later call to <a href=    "#longjmp">longjmp()</a>. When you first call setjmp(), its return value is zero. Later, when you call    longjmp(), the second argument of longjmp() is what the return value of setjmp() will be. Confused? Read    about <a href="#longjmp">longjmp()</a>.</p>    <i>Related topics:</i><br>     <strong><a href="#longjmp">longjmp()</a></strong>     <hr>    <h2><a name="signal">signal</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;signal.h&gt;  void ( *signal( int signal, void (* func) (int)) ) (int);</pre>        </td>      </tr>    </table>    <p>The signal() function sets <i>func</i> to be called when <i>signal</i> is recieved by your program.    <i>func</i> can be a custom signal handler, or one of these macros (defined in signal.h):</p>    <table bgcolor="#eeeeff">      <tr>        <td><strong>Macro</strong></td>        <td><strong>Explanation</strong></td>      </tr>      <tr>        <td>SIG_DFL</td>        <td>default signal handling</td>      </tr>      <tr>        <td>SIG_IGN</td>        <td>ignore the signal</td>      </tr>    </table>    <p>The return value of signal() is the address of the previously defined function for this signal, or    SIG_ERR is there is an error.</p>    <hr>    <h2><a name="srand">srand</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdlib.h&gt;  void srand( unsigned seed );</pre>        </td>      </tr>    </table>    <p>The function srand() is used to seed the random sequence generated by <a href="#rand">rand()</a>. For    any given <i>seed</i>, <a href="#rand">rand()</a> will generate a specific "random" sequence over and    over again.</p><pre>    srand( time(NULL) );    for( i = 0; i &lt; 10; i++ )      printf( "Random number #%d: %d\n", i, rand() );</pre>    <i>Related topics:</i><br>     <strong><a href="#rand">rand()</a>, <a href="stddate_details.html#time">time()</a>.</strong>     <hr>    <h2><a name="system">system</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdlib.h&gt;  int system( const char *command );</pre>        </td>      </tr>    </table>    <p>The system() function runs the given <i>command</i> as a system call. The return value is usually zero    if the command executed without errors. If <i>command</i> is NULL, system() will test to see if there is    a command interpreter available. Non-zero will be returned if there is a command interpreter available,    zero if not.</p>    <i>Related topics:</i><br>    <strong><a href="#exit">exit()</a>,</strong>     <hr>    <h2><a name="va_arg">va_arg</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  #include &lt;stdarg.h&gt;  type va_arg( va_list argptr, type );  void va_end( va_list argptr );  void va_start( va_list argptr, last_parm );</pre>        </td>      </tr>    </table>    <p>The va_arg() macros are used to pass a variable number of arguments to a function.</p>    <ol>      <li>First, you must have a call to va_start() passing a valid va_list and the mandatory first argument      of the function. This first argument describes the number of parameters being passed.</li>      <li>Next, you call va_arg() passing the va_list and the type of the argument to be returned. The return      value of va_arg() is the current parameter.</li>      <li>Repeat calls to va_arg() for however many arguments you have.</li>      <li>Finally, a call to va_end() passing the va_list is necessary for proper cleanup.</li>    </ol>    For example: <br>    <br>     <pre>    int sum( int, ... );    int main( void ) {          int answer = sum( 4, 4, 3, 2, 1 );      printf( "The answer is %d\n", answer );          return( 0 );    }        int sum( int num, ... ) {      int answer = 0;      va_list argptr;          va_start( argptr, num );      for( ; num &gt; 0; num-- )        answer += va_arg( argptr, int );          va_end( argptr );      return( answer );    }</pre>    <p>This code displays 10, which is 4+3+2+1.</p>  </body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -