I've imposed some limits for myself:
1) Lines that are not variable declarations, #includes, function prototypes,
or definitions, will be if possible, 80 characters in width.
2) To make this the same for everyone trying it, I will output what is suggested:
:DQuote:
Originally Posted by prog-bman
This way, everyone outputting Your name will all be using the same length item. Otherwise I could create an account with the longest name allowable, consisting of the character with the highest ascii value... ;)
3) I'll restrict (;)) my variable names to the length allowed for externally linked variables in C99. That is to say, 31 characters.
4) I will use only four spaces for indenting.
5) I'll use no unnecessary whitespace-only lines.
6) I'll assume the ascii character set.
Rather than just post the code itself, I wrote a program to make the program for me. Here is its source code:
Because it's the shorter of the two. :D Compile and run this, and you'll get my answer, which weighs in at 899 lines, none of which are whitespace.Code:#include <stdio.h>
#include <stdlib.h>
void fpvar( FILE *fp, int c )
{
char prefix[] = "ThisIsTheVariableForThe";
char *suffix[] = { "Letter_", "OneSpace" };
fprintf( fp, "%s%s", prefix, suffix[c==' '?1:0] );
if( c != ' ' )
{
fprintf( fp, "%c", c );
}
}
int main( void )
{
int x,y,z;
char letters[] = "Your name";
char *lines[] =
{
"#include <stdio.h>\n",
"int main( void )\n",
"{\n",
" char ",
" ",
" ",
" return 0;\n",
"}\n",
0,
};
FILE *fp = fopen("yourn.c", "w" );
if( !fp )
return 0;
for( x = 0; lines[x]; x++ )
{
fprintf( fp, "%s", lines[x] );
if( x == 3 )
{
fpvar( fp, letters[0] );
fputs( "=0,", fp );
fpvar( fp, letters[1] );
fputs( "=0,\n", fp );
}
if( x == 4 )
{
for( y = 0; y < 5; y+=2 )
{
fpvar( fp, letters[y+2] );
fputs( "=0,", fp );
fpvar( fp, letters[y+3] );
fputs( "=0,\n", fp );
fputs( lines[x], fp );
}
fpvar( fp, letters[y+2] );
fputs( "=0;\n", fp );
}
if( x == 5 )
{
for( y = 0; letters[y]; y++ )
{
for( z = 0; z < letters[y]; z++ )
{
fpvar( fp, letters[y] );
fputc( '=', fp );
fpvar( fp, letters[y] );
fputs( "+1;\n", fp );
fputs( lines[x], fp );
}
fputs( "putchar( ", fp );
fpvar( fp, letters[y] );
fputs( " );\n ", fp );
}
}
}
fclose( fp );
return 0;
}
Once I had the idea of what to do, it was funner to write a program to write it for me, than it was to actually write the output myself. :)
[edit] Minor pedantic editing. [/edit]
Quzah.
