打印出自身的程序

转自:http://www.cppblog.com/LeafCore/archive/2011/10/14/158294.html

简短的

#include < stdio.h >
main(){
char   * s = " #include<stdio.h>%cmain(){char *s=%c%s%c;printf(s,10,34,s,34);} " ;printf(s, 10 , 34 ,s, 34 );}

 


参考http://hi.baidu.com/atyuwen/blog/item/318ceb9b688ea7b2c8eaf412.html#0

'\"'使用了斜杠
main(){char* a="main(){char* a=%c%s%c;printf(a,34,a,34);}";printf(a,34,a,34);}中'\"'使用printf("%c",34);输出
'\n'可以使用printf("%c",10);输出

可读性佳的

#include < stdio.h >
main(){
    
char   * s = " #include<stdio.h>%cmain(){%c%cchar *s=%c%s%c;%c%cprintf(s,10,10,9,34,s,34,10,9,10);%c} " ;
    printf(s,
10 , 10 , 9 , 34 ,s, 34 , 10 , 9 , 10 );
}


 

// Copyright (c) LeafCore
#include < stdio.h >
void  main() {
    
char   * s = " //Copyright (c) LeafCore%c#include<stdio.h>%cvoid main() {%c%cchar *s=%c%s%c;%c%cprintf(s,10,10,10,9,34,s,34,10,9,10);%c} " ;
    printf(s,
10 , 10 , 10 , 9 , 34 ,s, 34 , 10 , 9 , 10 );
}


What a fantasy!
可执行文件生成自身的源文件

// Copyright (c) LeafCore
#include < stdio.h >
main(){
    FILE 
* fp = fopen( " file.c " , " w " );
    
char   * s = " //Copyright (c) LeafCore%c#include<stdio.h>%cmain(){%c%cFILE *fp=fopen(%cfile.c%c,%cw%c);%c%cchar *s=%c%s%c;%c%cfprintf(fp,s,10,10,10,9,34,34,34,34,10,9,34,s,34,10,9,10,9,10,9,10);%c%cfclose(fp);%c%creturn 0;%c} " ;
    fprintf(fp,s,
10 , 10 , 10 , 9 , 34 , 34 , 34 , 34 , 10 , 9 , 34 ,s, 34 , 10 , 9 , 10 , 9 , 10 , 9 , 10 );
    fclose(fp);
    
return   0 ;
}

运行生成的可执行文件,可生成自身的源文件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值