// C11_2.cpp : Defines the entry point for the console application. // 加入除錯程式碼 #include "stdafx.h" #include using namespace std; #include #include #include #ifdef _DEBUG void Check_String( char *string ); /* 原型宣告 */ void main( void ) { char try1[] = "My Word", *try2 = NULL, try3[] = ""; printf ( "字串分析 '%s'\n", try1 ); Check_String( try1 ); printf ( "字串分析 '%s'\n", try2 ); Check_String( try2 ); printf ( "字串分析 '%s'\n", try3 ); Check_String( try3 ); } /*測試字串是否為 NULL 值, */ /* 空字串, or 字串必須大於 2 個字元 */ void Check_String( char * string ) { assert( string != NULL ); /* 不能為 NULL */ assert( *string != '\0' ); /* 不能為空字串 */ assert( strlen( string ) > 2 ); /* 長度必須大於 2 字元*/ }