1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

give me the code

Discussion in 'C' started by krazytechno, Mar 7, 2010.

  1. krazytechno

    krazytechno New Member

    Joined:
    Mar 7, 2010
    Messages:
    38
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    knowing the computer world as deep as possible
    Location:
    kolkata,west bengal
    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");
    }
     
  2. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    17
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    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();
    }
    
     
  3. lipun4u

    lipun4u New Member

    Joined:
    Jan 25, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    Mumbai
    Home Page:
    Code:
    #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();
    }
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    The simplest program that will display its own source is an empty file.
     
  5. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
  6. rekha_sri

    rekha_sri New Member

    Joined:
    Feb 20, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    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;
    }
    
     

Share This Page