program that prints itself, how does it work?

后端 未结 4 1449
旧时难觅i
旧时难觅i 2020-12-29 07:42

I came across a program that prints itself on this site, i.e. it prints the program code.

The program code is:

#include 
char *program         


        
4条回答
  •  無奈伤痛
    2020-12-29 08:40

    This can be done using File handling. Save the program with any name and put that name in the open directory in fopen command. Like my program's name is hello.cpp.

    This is the following program

    #include 
    #include 
    int main()
    {
        FILE *fp;   
        fp=fopen("hello.cpp","r");
        char ch;
        while((ch=fgetc(fp))!=EOF)
        {
           printf("%c",ch);
         }
    }
    

提交回复
热议问题