Step1: 寫lottery.c~
//filename: lottery.c //2009-10-30, RayZ, 6/49大樂透 #include#include #include int main(int argc, char* argv[]) { int i; int no; int in; while(1) { printf("\n1: lottery \ \n0: exit \ \nenter is "); while(scanf("%d", &in)!=1) { fflush(stdin); printf("that's error\n"); return 0; } if(in == 0) break; else if(in != 1) printf("\nPlease enter:0~1\n"); else { for (i=0;i<6;i++) { no = rand()%49+1; if(i==5) printf("%d\n", no); else printf("%d,", no); } } } return 0; }
Step2: 寫Makefile~
# filename: Makefile # 2009-10-30, RayZ objects = lottery.o dell = $(ibm) ibm = $(phone) phone = number? lottery: $(objects) @gcc -o lottery $(objects) lottery.o: lottery.c @gcc -c lottery.c all: @echo $(phone) # @是不秀出echo命令 .PHONY:clean #預防目錄下真有一個clean file clean: -@rm -f $(objects) # -是rm出錯也不顯示
Step3: 編譯/執行~
$ make #產生lottery.o, lottery $ make clean #刪除lottery.o $ make all #測試用 $ ./lottery #執行lottery, 看能不能中個大獎
用vim來編輯Makefile,要記得檢查vim的設定環境(~/.vimrc)是否有set et(展開跳格鍵)。如果有就把它移走吧(或是:set noet)。為了避免Makefile: *** missing separator.Stop.
DOWNLOAD Here
[參考]
[1] wiki - make
[2] GNU Make 使用手冊
[3] cplusplus - c library
[4] The Open Group - c library
沒有留言:
張貼留言