posts - 8,  comments - 4,  trackbacks - 0
简短的
#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;
}
运行生成的可执行文件,可生成自身的源文件。
posted on 2011-10-14 13:50 leafcore 阅读(2738) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理



常用链接

留言簿

文章分类(2)

交流与思索

让生活更轻松

最新评论

阅读排行榜