打印自己的C程序
时间:2011-04-12 来源:小肥侠
很早以前写过这么一个程序,Turbo C++ 3.0编译通过。
#include "stdafx.h"
char str1[]="void printself(char * str){printf(\"\\\"\");for(int i=0;str[i]!='\\0';i++){if(str[i]=='\\\"')printf(\"%c%c\",'\\\\','\\\"');else if(str[i]=='\\\\')printf(\"%c%c\",'\\\\','\\\\');else printf(\"%c\",str[i]);}printf(\"\\\";\");};";
char selfstr[]="int main(int argc, char* argv[]){printf(\"%s\",\"#include \\\"stdafx.h\\\"\");printf(\"\\nchar str1[]=\");printself(str1);printf(\"\\nchar selfstr[]=\");printself(selfstr);printf(\"\\n%s\",str1);printf(\"\\n%s\",selfstr);return 0;}";
void printself(char * str){printf("\"");for(int i=0;str[i]!='\0';i++){if(str[i]=='\"')printf("%c%c",'\\','\"');else if(str[i]=='\\')printf("%c%c",'\\','\\');else printf("%c",str[i]);}printf("\";");};
int main(int argc, char* argv[]){printf("%s","#include \"stdafx.h\"");printf("\nchar str1[]=");printself(str1);printf("\nchar selfstr[]=");printself(selfstr);printf("\n%s",str1);printf("\n%s",selfstr);return 0;}