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

C program to print a source program itself

Discussion in 'C++' started by shri1609, Sep 30, 2010.

  1. shri1609

    shri1609 New Member

    Joined:
    Sep 30, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    C program to print the source program itself:

    Please help me to solve this program.
    i am not getting in this question we have read a file and print content of it or what source program to print. help ma out.
     
  2. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    Use the __FILE__ macro
     
  3. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    19
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    itz easy man...u just need to know the file handling...Open the own source file (with .c extention) and show it to the console....lolzz....it ia a very common question...
     
  4. kapilmishra16

    kapilmishra16 New Member

    Joined:
    Nov 9, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    kanpur
    actually I m unable to clearly understand your ques. what do you mean by source program?
     
  5. servalsoft

    servalsoft New Member

    Joined:
    Apr 17, 2010
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    0
    I think it is a simple as this:
    Assuming you are running your program from the same folder as the source file, as TechForum4U mentioned u can just open the file directly
    :
    :
    :
    ifstream in("source.c");

    string str("");
    while (getline(in, str))
    {
    cout << str;
    }
    :
    :

    of course you need to do the usual clean up and header imports. Thats my 5 cents.
     
  6. danyald

    danyald New Member

    Joined:
    Aug 2, 2010
    Messages:
    39
    Likes Received:
    1
    Trophy Points:
    0
    Home Page:
    Hey is simple. just open the source code file in your program through file handling. and all done.
    here are methods of File Handling
    http://www.google.com.pk/url?sa=t&s...yaGRDw&usg=AFQjCNFiaEP7PCchWeRb0eMTbMFHU5zusg
     
  7. Rakesh Kumar Pahwa

    Rakesh Kumar Pahwa New Member

    Joined:
    Jan 13, 2011
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    0
    everyone here is correct... but I agree with shabbir.. use __FILE__ macro... and also understand __LINE__ marcro for future....:)
     
  8. ASD

    ASD New Member

    Joined:
    Aug 9, 2011
    Messages:
    12
    Likes Received:
    0
    Trophy Points:
    0
    Is it to print the written program itself.....???
     

Share This Page