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 |
|
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 |
|
Code: CPP
krazytechno
like this
|
|
Mentor
|
![]() |
| 8Mar2010,13:54 | #4 |
|
The simplest program that will display its own source is an empty file.
krazytechno
like this
|
|
Pro contributor
|
![]() |
| 8Mar2010,16:44 | #5 |
|
Light Poster
|
|
| 8Mar2010,17:56 | #6 |
|
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
|



