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 .
Program that prints it's own source
Collapse
X
-
Originally posted by khajeddinhi :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? ) -
let me describe you more:Originally posted by SoujiroHmmm.. 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? )
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) .Comment
-
Hmm.. what operating system are u using.. can u use external executables.. and let those executables print the source code..Originally posted by khajeddinlet 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) .Comment
-
Someone has already beaten you to itOriginally posted by khajeddinhi :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 .
Comment
-
this is the simple code:
char*s="char*s= %c%s%c;main(){p rintf(s,34,s,34 );}";main(){pri ntf(s,34,s,34); }
Originally posted by r035198xComment
Comment