VB icon

A programm that displays its source

Email
Submitted on: 1/7/2015 2:22:00 AM
By: .rad (from psc cd)  
Level: Beginner
User Rating: By 3 Users
Compatibility: C++ (general)
Views: 1466
 
     A programm that displays its source. Compile, run executiable, and it will show the source code from wich it has been compiled. Just for fun...Useless, i guess ;)
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :A programm that displays its source
//**************************************
stdio.h
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: A programm that displays its source
// Description:A programm that displays its source. Compile, run executiable, and it will show the source code from wich it has been compiled. Just for fun...Useless, i guess ;)
// By: .rad (from psc cd)
//
// Returns:source code of itself
//**************************************

#include <stdio.h>
char szMyCode[] =
"void printf_strconst( char* str )\n"
"{\n"
"	do\n"
"	{\n"
"		switch( *str )\n"
"		{\n"
"		case \'\\n\':\n"
"			printf(\"\\\\n\\\"\");\n"
"			if( *(str+1) )\n"
"				printf(\"\\\"\");\n"
"			break;\n"
"		case \'\\\"\':\n"
"			printf(\"\\\"\");\n"
"			break;\n"
"		case \'\\\'\':\n"
"			printf(\"\\\'\");\n"
"			break;\n"
"		case \'\\\\\':\n"
"			printf(\"\\\\\\\\\");\n"
"			break;\n"
"		case \'%\':\n"
"			printf(\"%%\");\n"
"			str++;\n"
"			break;\n"
"		default:\n"
"			printf( \"%c\", *str );\n"
"		}\n"
"	}\n"
"	while( *++str );\n"
"	printf( \";\\n\\n\" );\n"
"}\n"
"\n"
"void main()\n"
"{\n"
"	printf( \"#include <stdio.h>\\n\\nchar szMyCode[] =\\n\\\"\" );\n"
"	printf_strconst( szMyCode );\n"
"	printf( \"%s\",szMyCode );\n"
"	printf( \"-=== THIS IS MY SOURCE! Press any key ===-\");\n"
"	getchar();\n"
"}\n";
void printf_strconst( char* str )
{
	do
	{
		switch( *str )
		{
		case '\n':
			printf("\\n\"");
			if( *(str+1) )
				printf("\n\"");
			break;
		case '\"':
			printf("\\\"");
			break;
		case '\'':
			printf("\\\'");
			break;
		case '\\':
			printf("\\\\");
			break;
		case '%':
			printf("%%");
			break;
		default:
			printf( "%c", *str );
		}
	}
	while( *++str );
	printf( ";\n\n" );
}
void main()
{
	printf( "#include <stdio.h>\n\nchar szMyCode[] =\n\"" );
	printf_strconst( szMyCode );
	printf( "%s",szMyCode );
	printf( "-=== THIS IS MY SOURCE! Press any key ===-");
	getchar();
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.