📄 all.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <meta name="generator" content= "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"> <title>Other Standard C Functions</title> <link href="../cppreference.css" rel="stylesheet" type="text/css"></head><body><table> <tr> <td> <div class="body-content"> <div class="header-box"> <a href="../index.html">cppreference.com</a> > <a href= "index.html">Other Standard C Functions</a> </div> <div class="name-format"> abort </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdlib.h> void abort( void );</pre> <p>The function abort() terminates the current program. Depending on the implementation, the return value can indicate failure.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="assert.html">assert</a><br> <a href="atexit.html">atexit</a><br> <a href="exit.html">exit</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> assert </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <assert.h> assert( exp );</pre> <p>The assert() macro is used to test for errors. If <em>exp</em> evaluates to zero, assert() writes information to <strong>stderr</strong> and exits the program. If the macro NDEBUG is defined, the assert() macros will be ignored.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="abort.html">abort</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> atexit </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdlib.h> int atexit( void (*func)(void) );</pre> <p>The function atexit() causes the function pointed to by <em>func</em> 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 non-zero on failure.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="abort.html">abort</a><br> <a href="exit.html">exit</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> bsearch </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdlib.h> void *bsearch( const void *key, const void *buf, size_t num, size_t size, int (*compare)(const void *, const void *) );</pre> <p>The bsearch() function searches <em>buf[0]</em> to <em>buf[num-1]</em> for an item that matches <em>key</em>, using a binary search. The function <em>compare</em> should return negative if its first argument is less than its second, zero if equal, and positive if greater. The items in the array <em>buf</em> should be in ascending order. The return value of bsearch() is a pointer to the matching item, or <strong>NULL</strong> if none is found.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="qsort.html">qsort</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> exit </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdlib.h> void exit( int exit_code );</pre> <p>The exit() function stops the program. <em>exit_code</em> is passed on to be the return value of the program, where usually zero indicates success and non-zero indicates an error.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="abort.html">abort</a><br> <a href="atexit.html">atexit</a><br> <a href="system.html">system</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> getenv </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdlib.h> char *getenv( const char *name );</pre> <p>The function getenv() returns environmental information associated with <em>name</em>, and is very implementation dependent. <strong>NULL</strong> is returned if no information about <em>name</em> is available.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="system.html">system</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> longjmp </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <setjmp.h> void longjmp( jmp_buf envbuf, int status );</pre> <p>The function longjmp() causes the program to start executing code at the point of the last call to <a href="setjmp.html">setjmp</a>(). <em>envbuf</em> is usually set through a call to <a href= "setjmp.html">setjmp</a>(). <em>status</em> becomes the return value of <a href="setjmp.html">setjmp</a>() and can be used to figure out where longjmp() came from. <em>status</em> should not be set to zero.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="setjmp.html">setjmp</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> qsort </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <stdlib.h> void qsort( void *buf, size_t num, size_t size, int (*compare)(const void *, const void *) );</pre> <p>The qsort() function sorts <em>buf</em> (which contains <em>num</em> items, each of size <em>size</em>) using <a href= "http://en.wikipedia.org/wiki/Quicksort">Quicksort</a>. The <em>compare</em> function is used to compare the items in <em>buf</em>. <em>compare</em> 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 <em>buf</em> in ascending order.</p> <div class="related-examples-format"> Example code: </div> <div class="related-examples"> <p>For example, the following bit of code uses qsort() to sort an array of integers:</p> <pre class="example-code"> int compare_ints( const void* a, const void* b ) { int* arg1 = (int*) a; int* arg2 = (int*) b; if( *arg1 < *arg2 ) return -1; else if( *arg1 == *arg2 ) return 0; else return 1; } int array[] = { -2, 99, 0, -743, 2, 3, 4 }; int array_size = 7; ... printf( "Before sorting: " ); for( int i = 0; i < array_size; i++ ) { printf( "%d ", array[i] ); } printf( "\n" ); qsort( array, array_size, sizeof(int), compare_ints ); printf( "After sorting: " ); for( int i = 0; i < array_size; i++ ) { printf( "%d ", array[i] ); } printf( "\n" ); </pre> <p>When run, this code displays the following output:</p> <pre class="example-code"> Before sorting: -2 99 0 -743 2 3 4 After sorting: -743 -2 0 2 3 4 99 </pre> </div> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="bsearch.html">bsearch</a><br> (C++ Algorithms) <a href="../cppalgorithm/sort.html">sort</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> raise </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <signal.h> int raise( int signal );</pre> <p>The raise() function sends the specified <em>signal</em> to the program. Some signals:</p> <table class="code-table"> <tr> <th class="code-table-th">Signal</th> <th class="code-table-th">Meaning</th> </tr> <tr> <td class="code-table-td">SIGABRT</td> <td class="code-table-td">Termination error</td> </tr> <tr> <td class="code-table-td">SIGFPE</td> <td class="code-table-td">Floating pointer error</td> </tr> <tr> <td class="code-table-td">SIGILL</td> <td class="code-table-td">Bad instruction</td> </tr> <tr> <td class="code-table-td">SIGINT</td> <td class="code-table-td">User presed CTRL-C</td> </tr> <tr> <td class="code-table-td">SIGSEGV</td> <td class="code-table-td">Illegal memory access</td> </tr> <tr> <td class="code-table-td">SIGTERM</td> <td class="code-table-td">Terminate program</td> </tr> </table> <p>The return value is zero upon success, nonzero on failure.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="signal.html">signal</a> </div> </div> </td> </tr> </table></body></html><hr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -