Can anybody tell me how can we print the source code as a output of the program? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 23

Can anybody tell me how can we print the source code as a output of the program?

15th Nov 2018, 6:09 AM
Prajakta
Prajakta - avatar
22 Answers
+ 28
For Python, you can just add this to your code: print(open(__file__).read()) For C: char c; FILE *f; f=fopen(__FILE__, "r"); while((c=fgetc(f))!=EOF){ putchar(c); } The others should be similar.
15th Nov 2018, 6:56 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 14
FYI / to help you use search, a program that prints its own source code is called a 'quine'.
15th Nov 2018, 7:08 PM
Kirk Schafer
Kirk Schafer - avatar
+ 10
Kishalaya Saha This is working Thanks for our help😇
15th Nov 2018, 7:05 AM
Prajakta
Prajakta - avatar
+ 6
Kirk Schafer Thanks for your help😊
16th Nov 2018, 3:42 AM
Prajakta
Prajakta - avatar
+ 6
徐寿成 Will you please talk in English?
18th Nov 2018, 2:20 AM
Prajakta
Prajakta - avatar
+ 5
You're welcome, Prajakta 😊
15th Nov 2018, 7:07 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 5
Python code. print(open(__file__).read())
16th Nov 2018, 7:45 AM
Anand Chaklasiya
Anand Chaklasiya - avatar
+ 5
Anand Chaklasiya Thanks 😊
16th Nov 2018, 10:35 AM
Prajakta
Prajakta - avatar
+ 4
i will give java source code later
15th Nov 2018, 6:27 PM
Alex
Alex - avatar
+ 4
Alex Thanks for your help😊 I'm waiting for your java source code. Thank You
16th Nov 2018, 3:42 AM
Prajakta
Prajakta - avatar
+ 3
if you know how to scan text files in any of the languages then put the source code in the .txt file
15th Nov 2018, 6:27 PM
Alex
Alex - avatar
+ 3
Alex What do you mean?
17th Dec 2018, 8:06 AM
Prajakta
Prajakta - avatar
+ 1
for c++ cout<<"whatever you want to print out"<<endl; ex: cout<<"Enter the value of a number"<<endl; cin>>num1; //cin is to take in information
16th Nov 2018, 4:13 PM
Zoe Rizzo
Zoe Rizzo - avatar
16th Nov 2018, 2:26 AM
danvetio
danvetio - avatar
0
sorry what I say is the same function in c is so fussy while in python is just one line(my English is not very good ,there may be some questions in my expression)
18th Nov 2018, 3:25 AM
smallwhite
smallwhite - avatar
0
oh i am very sorry
18th Dec 2018, 9:09 AM
Alex
Alex - avatar
0
no it isnt
18th Dec 2018, 7:22 PM
Alex
Alex - avatar
0
for php do $youvariable = file_get_contents(‘yourdomain’);
18th Dec 2018, 7:24 PM
Alex
Alex - avatar
- 1
😊
16th Nov 2018, 8:13 PM
rana
rana - avatar
- 1
Emilija Radvilate is super hot, seriously. Alex Stop spamming such comments. They're not related to programming, let alone these threads.
17th Dec 2018, 7:10 AM
Alex
Alex - avatar