give me the code

Go4Expert Member
7Mar2010,15:41   #1
krazytechno's Avatar
i want to write a programm such this programm will print the same code written on the editor.for eg
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
for(i=0;i<5;i++)
printf("MY NAME IS SUJEET");
}

OUTPUT:

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
for(i=0;i<5;i++)
printf("MY NAME IS SUJEET");
}
Skilled contributor
7Mar2010,15:59   #2
techgeek.in's Avatar
see this:-
Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
FILE *fp;
  int c;
   fp = fopen("prog.c","r");  //open the same program source code file 
   c = getc(fp) ;
   while (c!= EOF)
   {
   		putchar(c);
		c = getc(fp);
   }
   fclose(fp);
getch();
}
krazytechno like this
Light Poster
7Mar2010,16:57   #3
lipun4u's Avatar
Code: CPP
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
FILE *fp;
  int c;
   fp = fopen(__FILE__,"r")//use preprocessor to know the file name
   c = getc(fp) ;
   while (c!= EOF)
   {
     putchar(c);
        c = getc(fp);
   }
   fclose(fp);
getch();
}
krazytechno like this
Mentor
8Mar2010,13:54   #4
xpi0t0s's Avatar
The simplest program that will display its own source is an empty file.
krazytechno like this
Pro contributor
8Mar2010,16:44   #5
virxen's Avatar
http://dwcope.freeshell.org/projects/quine/
Light Poster
8Mar2010,17:56   #6
rekha_sri's Avatar
Use the following program.It will be give the correct ouput what u have expected.

Code:
#include <stdio.h>
int main ( void )
{
char filename[] = "file.txt";
FILE *file = fopen ( filename, "r" );
if (file != NULL)
{
char line [1024];
while(fgets(line,sizeof line,file)!= NULL) /* read a line from a file */
{
fprintf(stdout,"%s",line); //print the file contents on stdout.
}
fclose(file);
}
else
{
perror(filename); //print the error message on stderr.
}
return 0;
}
krazytechno like this