Home Forums C Programming C program to display own source code as output

Viewing 5 reply threads
  • Author
    Posts
    • #2030
      devangana
      Participant

      Hi All,

      Please help me to write a C program that outputs its own source code.

      With thanks and regards,

      Sandia

    • #3274
      yeswanth
      Participant

      i am not ab;e to write whole program at this time but i give you the clue that you should use file handling and open your file on which you are writting the program

    • #3275
      yeswanth
      Participant

      i think you should use file handling and open the file which you are making it will show your file on compiling the program

    • #3276
      Priyanka Rajput
      Participant

      MYFILE.CPP

      #include
      void main()
      {
      FILE  *fp;
      fp=fopen("myfile.cpp","r");
      char ch;
      while((ch=getchar(fp))!=EOF)
      putchar(ch);
      }
    • #3277
      Rashmi singh
      Participant
      #include
      main()
      {
      FILE *fp;
      char ch;
      fp=fopen("file_display.c","r"); //here 'file_display.c' may differ
      //reads char by char and stores it in 'ch' until the End of File
      while((ch=getc(fp))!=EOF)
      {
       putchar(ch);
      }
      fclose(fp);
      }
    • #3278
      Rashmi singh
      Participant

      Reply: C program to display own source code as output

      a simple way of doing this is Using “SYSTEM CALLS”

      main()
      {
       system("type filename.c");
      }
Viewing 5 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.