assert函数的原型
来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/08/05 12:36:06
assert函数的原型
![assert函数的原型](/uploads/image/z/15109232-32-2.jpg?t=assert%E5%87%BD%E6%95%B0%E7%9A%84%E5%8E%9F%E5%9E%8B)
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 */
}
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 */
}
assert的意思
请问assert的意义?
vc++中什么时候用assert()?assert()作用等同于哪个函数?
C 语言中assert的用法
函数原型是什么!
画波浪线的地方是什么,是什么函数,原型是什么
函数原型究竟怎样理解?
函数原型有什么作用
spoke 的原型spoke的原型
假定一个函数原型为“char*func(int n)”,则该函数的返回类型为
编写计算平均分的函数(函数原型为double average(double score[],int n))
C语言 的断言 assert 只有一个参数,Java 许多其他语言 的断言 可以多传一个字符串参数如,assert a>