// Copyright 2000 - Yuki(hir@suki.net) // マクロ定義の値により処理が変わる定義関数のサンプルプログラムです。 // コンパイルする場合はファイル名を "strcopy2.cpp" に変更して下さい。 #include #define DEBUG 1 // 数値によりレベルを切り換える。 char *StrCpy2(char *,char *); // プロトタイプ宣言。 char str00[]="abcd"; // str00 は "abcd"。 char str01[256],*sp; // str01 はポインタ配列。 void main() { #if DEBUG == 1 puts("LEVEL 1"); StrCpy2(str01,str00); #elif DEBUG == 2 puts("LEVEL 2"); StrCpy2(str01,str00); #elif DEBUG == 3 puts("LEVEL 3"); StrCpy2(str01,str00); #else puts("NORMAL"); #endif // デバッグの値ごとに表示を変更。 printf("str00:%s\n",str00); // str00 を表示。 printf("str01:%s\n",str01); // str01 を表示。 } char *StrCpy2(char *s1,char *s2){ int count=0; char *rp=s1; #if DEBUG >= 1 // レベル 1〜3 でコンパイルされる。       printf("%d\n",str00); printf("%d\n",str01); #endif #if DEBUG >= 2 // 2〜3 でコンパイル。 do{ *s1=*s2; #if defined DEBUG putchar(*s1); putchar(*s2); printf("%d\n",count++); // s1 に s2 をコピーし、カウントを増やして表示。 #endif s1++; s2++; }while(*s2); #endif #if DEBUG >= 3 // 3 でのみコンパイル。       printf("%d\n",rp); #endif return(rp); }