Home › Forums › C Programming › C program to display own source code as output
- This topic has 5 replies, 4 voices, and was last updated 16 years, 7 months ago by Rashmi singh.
Viewing 5 reply threads
- AuthorPosts
- November 13, 2007 at 10:36 pm #2030devanganaParticipant
Hi All,
Please help me to write a C program that outputs its own source code.
With thanks and regards,
Sandia
- March 10, 2008 at 9:09 pm #3274yeswanthParticipant
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
- March 10, 2008 at 9:11 pm #3275yeswanthParticipant
i think you should use file handling and open the file which you are making it will show your file on compiling the program
- March 14, 2008 at 5:39 am #3276Priyanka RajputParticipant
MYFILE.CPP
123456789#include<stdio.h><br />void main()<br />{<br />FILE *fp;<br />fp=fopen("myfile.cpp","r");<br />char ch;<br />while((ch=getchar(fp))!=EOF)<br />putchar(ch);<br />} - May 24, 2008 at 7:30 pm #3277Rashmi singhParticipant12345678910111213#include<stdio.h><br />main()<br />{<br />FILE *fp;<br />char ch;<br />fp=fopen("file_display.c","r"); //here 'file_display.c' may differ<br />//reads char by char and stores it in 'ch' until the End of File<br />while((ch=getc(fp))!=EOF)<br />{<br />putchar(ch);<br />}<br />fclose(fp);<br />}
- May 24, 2008 at 7:41 pm #3278Rashmi singhParticipant
Reply: C program to display own source code as output
a simple way of doing this is Using “SYSTEM CALLS”
1234main()<br />{<br />system("type filename.c");<br />}
- AuthorPosts
Viewing 5 reply threads
- The forum ‘C Programming’ is closed to new topics and replies.