C/C++ program that prints its own source code as its output

后端 未结 8 2321
天命终不由人
天命终不由人 2020-11-29 08:25

Wikipedia says it\'s called a quine and someone gave the code below:

char*s=\"char*s=%c%s%c;main(){printf(s,34,s,34);}\";main(){printf(s,34,s,34);}
         


        
8条回答
  •  天涯浪人
    2020-11-29 09:07

    #include
    
    int main(void)
    {
        char a[20],ch;
        FILE *fp;
        // __FILE__ Macro will store File Name to the array a[20]
        sprintf(a,__FILE__);  
        // Opening the file in Read mode 
        fp=fopen(a,"r");      
        // Taking character by character from file, 
        // you can also use fgets() to take line by line
        while((ch=fgetc(fp))!=EOF)  
        printf("%c",ch);
        return 0;
    }                              
    

提交回复
热议问题