close
範例碼(一):C/C++ 語言,自訂函數及標頭檔,範例如下,主程式 main.c 檔。
#include <stdio.h> #include <stdlib.h> /* * include "自製標頭檔.h" */ #include "./str.h" /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { char *receive=str_include(); printf("%s",receive); printf("%s",str_include()); int send_parament=100; printf("%d",int_include(send_parament)); return 0; }
範例碼(二):建立標頭檔,str.h 檔,並在主程式 main.c 檔引入。
char *str_include(void) { char *str="自製標頭檔...\n"; return str; } int int_include(int receive_parament) { receive_parament=200; return receive_parament; }
範例碼(三):以上兩個(main.c , str.h)檔案經過前置處理器 #include 處理後,str.h 檔案會被合併進 main.c。
##include <stdio.h> #include <stdlib.h> /* * include "自製褾頭檔.h" */ #include "./str.h" /* run this program using the console pauser or add your own getch, system("pause") or input loop */ char *str_include(void) { char *str="自製標頭檔...\n"; return str; } int int_include(int receive_parament) { receive_parament=200; return receive_parament; } int main(int argc, char *argv[]) { char *receive=str_include(); printf("%s",receive); printf("%s",str_include()); int send_parament=100; printf("%d",int_include(send_parament)); return 0; } //Answer: //自製標頭檔... //自製標頭檔... //200
文章標籤
全站熱搜
留言列表