当前位置:编程学习 > C/C++ >>

打印出自身的程序

简短的#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;

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

补充:软件开发 , C语言 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,