give me the code

krazytechno's Avatar, Join Date: Mar 2010
Go4Expert Member
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");
}
techgeek.in's Avatar, Join Date: Dec 2009
Skilled contributor
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
lipun4u's Avatar, Join Date: Jan 2010
Light Poster
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
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
The simplest program that will display its own source is an empty file.
krazytechno like this
virxen's Avatar, Join Date: Nov 2009
Pro contributor
http://dwcope.freeshell.org/projects/quine/
rekha_sri's Avatar, Join Date: Feb 2010
Light Poster
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