Code:
int main ( ) {
char histogram[256] = { 0 };
char buff[256];
int i;
fgets( buff, 256, stdin );
for ( i = 0 ; i < 256 && buff[i] != '\0' ; i++ )
histogram[buff[i]]++;
for ( i = 0 ; i < 256 ; i++ )
printf( "%d %d\n", i, histogram[i] );
}
Fancy changing the buffer size by hand? (imagine a program with 10K lines instead).
Or even just reading the code and trying to figure out in each instance what that particular number really means.
Compare with
Code:
#define BUFF_SIZE 256
#define MAX_CHAR 256
int main ( ) {
char histogram[MAX_CHAR] = { 0 };
char buff[BUFF_SIZE];
int i;
fgets( buff, BUFF_SIZE, stdin );
for ( i = 0 ; i < BUFF_SIZE && buff[i] != '\0' ; i++ )
histogram[buff[i]]++;
for ( i = 0 ; i < MAX_CHAR ; i++ )
printf( "%d %d\n", i, histogram[i] );
}
The code is much easier to read, and changing any of the constants is a snap.