473,395 Members | 1,623 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Program that prints it's own source

hi :i have to write a program which should print its "source code" for output.how to do this.please make me a example of "source code" and make a definition of "source code".program shouldn't contain any file .
Jan 15 '07 #1
5 2676
Soujiro
35
hi :i have to write a program which should print its "source code" for output.how to do this.please make me a example of "source code" and make a definition of "source code".program shouldn't contain any file .

Hmmm.. its not that hard though.. you only need to use

FILE *fp = fopen(filename,"r") "r" means read only..

and read its byte by int read = fgetc( fp ).. use a loop

now use printf(":)") to print the read but first cast it to (char) (ex. char m = (char)read; ).. this is so because fgetc returns an unsigned char cast to an int..
or what do you mean by output..(where?)
Jan 15 '07 #2
Hmmm.. its not that hard though.. you only need to use

FILE *fp = fopen(filename,"r") "r" means read only..

and read its byte by int read = fgetc( fp ).. use a loop

now use printf(":)") to print the read but first cast it to (char) (ex. char m = (char)read; ).. this is so because fgetc returns an unsigned char cast to an int..
or what do you mean by output..(where?)
let me describe you more:
1) i'm not permitted to use any file in my program.
2)i have to print my source code ( in consul)(output is source code) .
Jan 15 '07 #3
Soujiro
35
let me describe you more:
1) i'm not permitted to use any file in my program.
2)i have to print my source code ( in consul)(output is source code) .
Hmm.. what operating system are u using.. can u use external executables.. and let those executables print the source code..
Jan 16 '07 #4
r035198x
13,262 8TB
hi :i have to write a program which should print its "source code" for output.how to do this.please make me a example of "source code" and make a definition of "source code".program shouldn't contain any file .
Someone has already beaten you to it

http://www.thescripts.com/forum/thread588410.html
Jan 16 '07 #5
this is the simple code:

char*s="char*s=%c%s%c;main(){printf(s,34,s,34);}"; main(){printf(s,34,s,34);}





Someone has already beaten you to it

http://www.thescripts.com/forum/thread588410.html
Jan 17 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Prashanth Badabagni | last post by:
Hi , I'm Prashanth Badabagni .. I have and idea how a program prints it's own source code .. void main() { FILE *P; char *file,c; strcpy(file,__FILE__); p=fopen(file,"r");
10
by: Robert Rotstein | last post by:
Following is a C program, taken from http://en.wikipedia.org/wiki/Quine#Sample_quine_in_C, which has the curious property that, when executed, it produces its own source code as output. ...
9
by: gg | last post by:
If somebody asks me to write a program that prints itself ( quine ) can I write the following program as an answer - #include <iostream> #include <fstream> using namespace std; int main (...
11
by: lovecreatesbea... | last post by:
Ken Thompson mentioned a self-reproducing program that products an exact copy of its source code as output in his 1983 Turing paper, http://www.acm.org/classics/sep95/ . Can this be done in C? How...
14
by: hall.jeff | last post by:
I wrote the following simple program to loop through our help files and fix some errors (in case you can't see the subtle RE search that's happening, we're replacing spaces in bookmarks with _'s) ...
3
by: haelly | last post by:
Write a program that prompts the user to enter three different integer values.If the values are not different, the program prints a message"equal values" and terminates(hint: use the return...
1
by: haelly | last post by:
write a program that prompts the user to enter three different positive integer values.If the values are not different, the program prints a message"equal value" and terminates(hint:use the return...
21
by: mikhal80 | last post by:
Is it possible to write a program which would print out it's own source code, using C++?
9
by: tvnaidu | last post by:
This is just small plain HTML program wtote manually (since I am new to web programming, may be some tools I can use I think), this program loaded onto microcontroller with small foot print web...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.