程序打印自身代码的两种方法
方法一:利用fopen,打开可运行程序相应的source code file
/***************************************** code writer : EOF code file : print_my_self.c code date : 2014.08.01 e-mail: jasonleaster@gmail.com code purpose : Aha, print out myself! ******************************************/ #include <stdio.h> #include <fcntl.h> #define BUFFSIZE 1024 char buffer[BUFFSIZE]; int main() { FILE* fp = NULL; int ret = 0; if((fp = fopen("./print_my_self.c","r")) == NULL) { printf("Damn it,fopen failed "); return 0; } while((ret = fread(buffer,sizeof(char),BUFFSIZE-1,fp)) > 0) { buffer[ret-1] = '