The following program demonstrates your tab width, indentation style, and various other aspects of your code style. Please write it (in verbatim) in your preferred style. Remember to use spaces instead of tabs, as shitchan automatically converts tabs into 3 space characters.
[code]#include "stdio.h"
int main (void)
{ int x;
char c = 'a';
float y = 0;
for (x = 0; x < 10; x++)
{ if (x % 2 == 0)
printf ("%d\n", x);
else
{ printf ("%c\n", c);
c +=1;
}
}
return 0;
}
Name:
Anonymous2010-01-24 16:53
#include "stdio.h"
int main (void)
{
int x = 0;
char c = 'a';
float y = 0;
for(; x < 10; x++)
{
if(x%2 == 0)
{
printf("%d\n", x);
}
else
{
printf("%c\n", c);
c += 1;
}
}
return 0;
}
(What was the float for?)
There are additional things this short code does not demonstrate. I tend to place ternary operations in parenthesis. The simplicity of the statement executed by the if...else branch decides whether I use more lines or put that part on a single line. I declare purpose-related, type-same variables in the same line. I have specific spacings: between adjacent classes (three lines), between adjacent functions/methods and their comments (also two lines). If I declare, initialize, set, or compare variables, I make sure there are spaces, save for the modulus operator. Putting spaces sparsely on the outside of parenthesis only where it assists readability.
Here's an example of something I'm oft to do when using Java: System.arraycopy(src,0, dest,0, (j-1));
The first two and the next two parameters may be related but there's no reason to space them like that: I just do.