Sunday, September 29, 2013

Quine



  • Quine
    Computing

  • A quine is a computer program which takes no input and produces a copy of its own source code as its only output.
    There are two method doing this
    1.Using File Handling
    2.Using String

    Method 1
    #include <stdio.h>
    #include <string.h>

    main()
    {
       FILE *fp;
       char buff[255];

       fp = fopen("input.txt", "r");
       if( fp != NULL ){
          while ( !feof(fp ) ){
             memset(buff, '\0', sizeof( buff) );
             fgets(buff, 255, (FILE*)fp);
             printf("%s", buff );
          }
          fclose(fp);
       }
    }

    Method 2

    #include <iostream>
    #include<string>
    using namespace std;

    int main()
    {  string s="#include <iostream>@"
    "#include<string>@"
    "using namespace std;@"
    "int main()@"
    "{  string s=;@"
     "for(int i=0;i<s.length();i++)@"
       "if(s[i]=='@')@"
       "cout<<endl;@"
       "else@"
      " cout<<s[i];@"
      " return 0;@"
    "}@";
       for(int i=0;i<s.length();i++)
       if(s[i]=='@')
       cout<<endl;
       else
       cout<<s[i];
       return 0;
    }



  • No comments:

    Post a Comment