aboutsummaryrefslogtreecommitdiff
path: root/ch6 (follow)
AgeCommit message (Collapse)AuthorFilesLines
2016-06-16The massive astyle sweep!zlg6-12/+12
Code style should be consistent now. All future commits will be run through astyle or they will be amended.
2015-12-05Solve Exercise 6-6: A simple `#define` processorzlg2-2/+200
This exercise is probably the most challenging "function puzzle" thus far. Modifying getword(), using various states, and the hashtable all create an example of how small building blocks can work together to make something. The implementation is very simple and nowhere near completely supporting '#define', but that's not the point. To properly support it, you'd need to build an entire preprocessor/parser, and that's far beyond the scope of both the exercise and book.
2015-11-20Solve Exercise 6-5: undef()zlg1-0/+107
We're getting close to more useful data structures! Wee!
2015-11-07Solve Exercise 6-4: Highest Word Frequencyzlg1-0/+177
This exercise was good practice to get back into the mindset of programming. It's not a pretty solution, but it works. I may end up coming back to this solution, because I feel like I've missed something that would make this exercise simpler.
2015-08-04Solve Exercise 6-03: Word cross-referencingzlg1-0/+190
2015-03-08Solve Exercise 6-02: Common prefix printingzlg1-0/+239
2015-03-03Solve Exercise 6-01: Enhanced `getword`zlg1-0/+170
This exercise improved my understanding of identifying comments and quotes by focusing on edge cases.
er.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include <stdio.h>

/* The C Programming Language: 2nd Edition
 *
 * Exercise 2-10: Rewrite the function 'lower', which converts upper case
 * letters to lower case, with a conditional expression instead of if-else.
 *
 * Answer: The tertiary ?: operators also _evaluate_, so they can be used in
 * a lot of different places.
 */

int lower(int c) {
	return (c >= 'A' && c <= 'Z') ? c + 'a' - 'A' : c;
}

int main() {
	char foo = 'F';
	printf("The following letter should be lowercase: %c\n", lower(foo));
	return 0;
}