Skip to content

Commit

Permalink
Updated coding convention
Browse files Browse the repository at this point in the history
  • Loading branch information
soffes committed Aug 11, 2011
1 parent ec7a178 commit df631e0
Show file tree
Hide file tree
Showing 25 changed files with 70 additions and 96 deletions.
2 changes: 1 addition & 1 deletion Readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ There are quite possibly better solutions to the exercises than what I have writ

## Conventions

The book doesn't add brackets for one line control structures. This drives me nuts. I have added them for my own sanity, so examples may vary slightly in appearance from those in the book. Their functionality will be identical.
The book doesn't add brackets for one line control structures, `/* */` style comments, and some brackets silliness. This drives me nuts. I have tweaked them for my own sanity, so examples may vary slightly in appearance from those in the book. Their functionality will be identical.

## License

Expand Down
13 changes: 6 additions & 7 deletions examples/1.2-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

#include <stdio.h>

/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300 */
main()
{
// print Fahrenheit-Celsius table
// for fahr = 0, 20, ..., 300
main() {
int fahr, celsius;
int lower, upper, step;

lower = 0; /* lower limit of temperature table */
upper = 300; /* upper limit */
step = 20; /* step size */
lower = 0; // Lower limit of temperature table
upper = 300; // Upper limit
step = 20; // Step size

fahr = lower;
while (fahr <= upper) {
Expand Down
13 changes: 6 additions & 7 deletions examples/1.2-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

#include <stdio.h>

/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300; floating-point version */
main()
{
// Print Fahrenheit-Celsius table
// for fahr = 0, 20, ..., 300; floating-point version
main() {
float fahr, celsius;
int lower, upper, step;

lower = 0; /* lower limit of temperature table */
upper = 300; /* upper limit */
step = 20; /* step size */
lower = 0; // Lower limit of temperature table
upper = 300; // Upper limit
step = 20; // Step size

fahr = lower;
while (fahr <= upper) {
Expand Down
5 changes: 2 additions & 3 deletions examples/1.3-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

#include <stdio.h>

/* print Fahrenheit-Celsius table */
main()
{
// Print Fahrenheit-Celsius table
main() {
int fahr;

for (fahr = 0; fahr <= 300; fahr = fahr + 20) {
Expand Down
5 changes: 2 additions & 3 deletions examples/1.4-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
#define UPPER 300
#define STEP 20

/* print Fahrenheit-Celsius table */
main()
{
// Print Fahrenheit-Celsius table
main() {
int fahr;

for (fahr = LOWER; fahr <= UPPER; fahr = fahr + STEP) {
Expand Down
5 changes: 2 additions & 3 deletions examples/1.5.1-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

#include <stdio.h>

/* copy input to output; 1st version */
main()
{
// Copy input to output; 1st version
main() {
int c;
c = getchar();
while (c != EOF) {
Expand Down
5 changes: 2 additions & 3 deletions examples/1.5.1-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

#include <stdio.h>

/* copy input to output; 1st version */
main()
{
// Copy input to output; 1st version
main() {
int c;

while ((c = getchar()) != EOF) {
Expand Down
5 changes: 2 additions & 3 deletions examples/1.5.2-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

#include <stdio.h>

/* count characters in input; 1st version */
main()
{
// Count characters in input; 1st version
main() {
long nc;

nc = 0;
Expand Down
5 changes: 2 additions & 3 deletions examples/1.5.2-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

#include <stdio.h>

/* count characters in input; 2nd version */
main()
{
// Count characters in input; 2nd version
main() {
double nc;

nc = 0;
Expand Down
5 changes: 2 additions & 3 deletions examples/1.5.3-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

#include <stdio.h>

/* count lines in input */
main()
{
// Count lines in input
main() {
int c, nl;

nl = 0;
Expand Down
9 changes: 4 additions & 5 deletions examples/1.5.4-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

#include <stdio.h>

#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */
#define IN 1 // Inside a word
#define OUT 0 // Outside a word

/* count lines, words, and characters in input */
main()
{
// Count lines, words, and characters in input
main() {
int c, nl, nw, nc, state;

state = OUT;
Expand Down
5 changes: 2 additions & 3 deletions examples/1.6-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

#include <stdio.h>

/* count digits, white space, and others */
main()
{
// Count digits, white space, and others
main() {
int c, i, nwhite, nother;
int ndigit[10];

Expand Down
10 changes: 4 additions & 6 deletions examples/1.7-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

int power(int m, int n);

/* test power function */
main()
{
// Test power function
main() {
int i;

for (i = 0; i < 10; ++i) {
Expand All @@ -15,9 +14,8 @@ main()
return 0;
}

/* power: raise base to n-th power; n >= 0 */
int power(int base, int n)
{
// Power: raise base to n-th power; n >= 0
int power(int base, int n) {
int i, p;

p = 1;
Expand Down
4 changes: 1 addition & 3 deletions exercises/1-10.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
// `\t`, each backspace by a `\b`, and each backslash by a `\\`. This makes the
// tabs and backspaces visible in an unambiguous way.


#include <stdio.h>

main()
{
main() {
int c;

while ((c = getchar()) != EOF) {
Expand Down
7 changes: 3 additions & 4 deletions exercises/1-12.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

#include <stdio.h>

#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */
#define IN 1 // Inside a word
#define OUT 0 // Outside a word

main()
{
main() {
int c, previous, state;

state = OUT;
Expand Down
11 changes: 5 additions & 6 deletions exercises/1-13-1.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

#include <stdio.h>

#define MAX 20 /* maximum length of a word */
#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */
#define MAX 20 // Maximum length of a word
#define IN 1 // Inside a word
#define OUT 0 // Outside a word

/* horizontal histogram of word lengths */
main()
{
// Horizontal histogram of word lengths
main() {
int state = OUT;
int cw = 0;
int nwords[MAX], i, x, c;
Expand Down
11 changes: 5 additions & 6 deletions exercises/1-13-2.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

#include <stdio.h>

#define MAX 20 /* maximum length of a word */
#define IN 1 /* inside a word */
#define OUT 0 /* outside a word */
#define MAX 20 // Maximum length of a word
#define IN 1 // Inside a word
#define OUT 0 // Outside a word

/* vertical histogram of word lengths */
main()
{
// Vertical histogram of word lengths
main() {
int state = OUT;
int nwords[MAX], cw, i, x, a, c, highest;
cw = highest = 0;
Expand Down
3 changes: 1 addition & 2 deletions exercises/1-14.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

#define LIMIT 'z'-' '

main()
{
main() {
int nchars[LIMIT], i, x, c;

for (i = 0; i < LIMIT; ++i) {
Expand Down
13 changes: 6 additions & 7 deletions exercises/1-3.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@

#include <stdio.h>

/* print Fahrenheit-Celsius table
for fahr = 0, 20, ..., 300; floating-point version */
main()
{
// Print Fahrenheit-Celsius table
// for fahr = 0, 20, ..., 300; floating-point version
main() {
float fahr, celsius;
int lower, upper, step;

lower = 0; /* lower limit of temperature table */
upper = 300; /* upper limit */
step = 20; /* step size */
lower = 0; // Lower limit of temperature table
upper = 300; // Upper limit
step = 20; // Step size

fahr = lower;
printf("Fahrenheit | Celsius\n");
Expand Down
13 changes: 6 additions & 7 deletions exercises/1-4.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@

#include <stdio.h>

/* print Celsius-Fahrenheit table
for celsius = 0, 20, ..., 300; floating-point version */
main()
{
// Print Celsius-Fahrenheit table
// for celsius = 0, 20, ..., 300; floating-point version
main() {
float fahr, celsius;
int lower, upper, step;

lower = 0; /* lower limit of temperature table */
upper = 300; /* upper limit */
step = 20; /* step size */
lower = 0; // Lower limit of temperature table
upper = 300; // Upper limit
step = 20; // Step size

celsius = lower;
printf("Celsius | Fahrenheit\n");
Expand Down
5 changes: 2 additions & 3 deletions exercises/1-5.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

#include <stdio.h>

/* print Fahrenheit-Celsius table */
main()
{
// Print Fahrenheit-Celsius table
main() {
int fahr;

for (fahr = 300; fahr >= 0; fahr = fahr - 20) {
Expand Down
3 changes: 1 addition & 2 deletions exercises/1-6.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <stdio.h>

main()
{
main() {
printf("%d\n", getchar() != EOF);
}
3 changes: 1 addition & 2 deletions exercises/1-7.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <stdio.h>

main()
{
main() {
printf("EOF: %d\n", EOF);
}
3 changes: 1 addition & 2 deletions exercises/1-8.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

#include <stdio.h>

main()
{
main() {
int c, nb, nt, nl;

nb = 0;
Expand Down
3 changes: 1 addition & 2 deletions exercises/1-9.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

#include <stdio.h>

main()
{
main() {
int c, previous;

while ((c = getchar()) != EOF) {
Expand Down

0 comments on commit df631e0

Please sign in to comment.