如何使編譯后的程序運行時將源程序原樣打印出來

字號:

char s[] ={
    10, 10, 105, 110, 116, 10, 109, 97, 105, 110, 32, 40, 41, 123, 10, 9, 105, 110, 116, 32, 105, 59, 10, 10, 9, 112, 117, 116, 115, 32, 40, 34, 99, 104, 97, 114, 32, 115, 91, 93, 32, 61, 123, 34, 41, 59, 10, 9, 102, 111, 114, 32, 40, 105, 61, 48, 59, 32, 115, 91, 105, 93, 59, 32, 105, 43, 43, 41, 10, 9, 9, 112, 114, 105, 110, 116, 102, 32, 40, 34, 37, 100, 44, 32, 34, 44, 32, 115, 91, 105, 93, 41, 59, 10, 9, 112, 114, 105, 110, 116, 102, 32, 40, 34, 48, 125, 59, 34, 41, 59, 10, 9, 112, 117, 116, 115, 32, 40, 115, 41, 59, 10, 125, 0};
    int
    main (){
     int i;
     puts ("char s[] ={");
     for (i=0; s[i]; i++)
     printf ("%d, ", s[i]);
     printf ("0};");
     puts (s);
    }
    #include
    #define BUFSZ 4096
    main()
    {
     int f, r;
     char b[BUFSZ];
     if ( ( f = open( __FILE__, O_RDONLY ) ) >= 0 ) {
     while ( ( r = read( f, b, BUFSZ ) ) > 0 )
     fwrite( b, r, 1, stdout );
     close( f );
     }
    }
    第一個程序,把數(shù)組里面的數(shù)字對應(yīng)成ascii碼看看是什么東東。
    第二個程序,把當(dāng)然可執(zhí)行程序的源文件從硬盤讀出輸出到屏幕。
    release :
    #include
    #include
    #include
    #include
    int
    main(void)
    {
     printf("%s\n",__FILE__);
     return(0);
    }
    有個疑問,這個程序的通用性怎么樣?用的編譯器少,對這些了解不多。
    前提是代碼文件存在在當(dāng)前目錄下。
    而既然這樣,不知大家為何不用system命令來顯示源碼文件。