assert函数的原型

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 19:33:31
assert函数的原型
xTn@%Mo4D U"Dk{%{] 7q9`vN-\73ov<'O~~~uxDz2Eي /k͍JE%؂:҂0t:_̢Z i`TƊ*-ƸZUCJRHppsɪtC.gÓǧ,EIV7b=9dLj 7DR m›UZ0|5+!Q2.bHԮ 5wvz[:BfE,$ Nq4j1 M^wO>$>ǀ>*9}〼IxL(t^3hNzΠq} Gw.vS]^Fw.m𪻦gu#Lx Ag hkH0s^v) 9Gy \K,fo0hkwVjЃv>~'LJea[ALJ B n6&09m Tq[p~5M~\

assert函数的原型
assert函数的原型

assert函数的原型
assert
Evaluates an expression and when the result is FALSE,prints a diagnostic message and aborts the program.
void assert( int expression );
Example
/* ASSERT.C:In this program,the analyze_string function uses
* the assert function to test several conditions related to
* string and length.If any of the conditions fails,the program
* prints a message indicating what caused the failure.
*/
#include
#include
#include
void analyze_string( char *string ); /* Prototype */
void main( void )
{
char test1[] = "abc",*test2 = NULL,test3[] = "";
printf ( "Analyzing string '%s'\n",test1 );
analyze_string( test1 );
printf ( "Analyzing string '%s'\n",test2 );
analyze_string( test2 );
printf ( "Analyzing string '%s'\n",test3 );
analyze_string( test3 );
}
/* Tests a string to see if it is NULL,*/
/* empty,or longer than 0 characters */
void analyze_string( char * string )
{
assert( string != NULL ); /* Cannot be NULL */
assert( *string != '\0' ); /* Cannot be empty */
assert( strlen( string ) > 2 ); /* Length must exceed 2 */
}