assert函数的原型

[复制链接]
查看: 156|回复: 0

assert函数的原型

[复制链接]
查看: 156|回复: 0
猛蹬

279

主题

1024

回帖

4014

积分

荣誉会员

积分
4014

社区居民

猛蹬 2011-9-28 11:41:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享受更多内容,了解更多户外知识,让你轻松享受户外!

您需要 登录 才可以下载或查看,没有账号?立即注册

×
assertEvaluates an expression and when the result is FALSE, prints a diagnostic message and aborts the program&#46;void assert( int expression );Example/* ASSERT&#46;C: In this program, the analyze_string function uses * the assert function to test several conditions related to * string and length&#46; If any of the conditions fails, the program * prints a message indicating what caused the failure&#46; */#include <stdio&#46;h>#include <assert&#46;h>#include <string&#46;h>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 */}
”济源户外网” www.jyhww.com 倡导“积极健康”的生活方式、崇尚“自然、和谐、真诚、友爱”的人文精神,以“自主、绿色、氧气、阳光、健康、友谊”为宗旨,由热爱生活、热爱大自然的群体组成。是户外运动者的家园,也是个人挑战自我。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|济源户外网-天韵茗茶 | 豫ICP备10211396号-1

GMT+8, 2025-1-12 06:56 , Processed in 0.057146 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.