--- /dev/null
+/* Desc: Counts blanks, tabs, and newlines */
+/* Ref/Attrib: K&R 2nd Ed. Exercise 1-8 */
+
+#include <stdio.h>
+int main() {
+ int c, cb, ct, cnl;
+
+ /* Initialize counters */
+ cb = 0;
+ ct = 0;
+ cnl = 0;
+
+ /* User prompt loop. */
+ while((c = getchar()) != EOF) {
+ /* Detect blanks character */
+ if(c == ' ')
+ ++cb;
+
+ /* Detect tab character */
+ if(c == '\t')
+ ++ct;
+
+ /* Detect newline character */
+ if(c == '\n')
+ ++cnl;
+ };
+
+ /* Print results. */
+ printf("Blnk:\t%d\n", cb);
+ printf("Tabs:\t%d\n", ct);
+ printf("Nwln:\t%d\n", cnl);
+ printf("\nDone.\n");
+};
+
+/* Author: Steven Baltakatei Sandoval
+ License: GPLv3+ */
--- /dev/null
+/* Desc: Print tabs, backspaces, and backslashes with escape backslashes */
+/* Ref/Attrib: K&R 2nd Ed. Exercise 1-10 */
+
+#include <stdio.h>
+int main() {
+ int c;
+
+ /* User prompt loop. */
+ while((c = getchar()) != EOF) {
+
+ if(c == '\t') {
+ /* If c is tab */
+ printf("\\t");
+ } else if(c == '\b') {
+ /* If c is backspace */
+ printf("\\b");
+ } else if(c == '\\') {
+ /* If c is backslash */
+ printf("\\\\");
+ } else
+ putchar(c);
+
+ };
+
+ printf("\nDone.\n");
+};
+
+/* Author: Steven Baltakatei Sandoval
+ License: GPLv3+ */
--- /dev/null
+/* Desc: Squeezes consecutive blanks */
+/* Ref/Attrib: K&R 2nd Ed. Exercise 1-9 */
+
+#include <stdio.h>
+int main() {
+ int c, cb;
+
+ /* Initialize counters */
+ cb = 0; // count of blanks
+
+ /* User prompt loop. */
+ while((c = getchar()) != EOF) {
+
+ if(c == ' ') {
+ /* If c is blank */
+ ++cb;
+ } else if (cb <= 0) {
+ /* If last round was not a blank AND c is not a blank */
+ putchar(c);
+ } else {
+ /* Last round was a blank AND c is not a blank */
+ cb = 0;
+ printf(" ");
+ putchar(c);
+ };
+ };
+
+ if(cb > 0) {
+ /* If EOF received after blank(s) */
+ printf(" ");
+ };
+
+ printf("\nDone.\n");
+};
+
+/* Author: Steven Baltakatei Sandoval
+ License: GPLv3+ */
<section|Terminology>
<\description-compact>
+ <item*|assignment>An expression in which a variable is set to a value.
+ For example, in the expression <hgroup|<cpp|x = 1>>, the variable <cpp|x>
+ is set to the value <cpp|1> because <cpp|x> is to the left of the equals
+ sign \ \P<cpp|=>\Q. The value of the entire expression is equal to the
+ value of the left hand side (i.e. <cpp|x> in this example) after the
+ assignment is performed. For example, the following C code will print
+ \P<cpp|true>\Q:
+
+ <\cpp-code>
+ #include \<less\>stdio.h\<gtr\>
+
+ int main() {
+
+ \ \ int c;
+
+ \ \ if( (c = 7) == 7 )
+
+ \ \ \ \ printf("true");
+
+ \ \ else
+
+ \ \ \ \ printf("false");
+
+ };
+ </cpp-code>
+
+ As another example, the following lines are equivalent:
+
+ <\cpp-code>
+ a = b = c = 0;
+
+ a = ( b = ( c = 0 ) );
+ </cpp-code>
+
<item*|declaration<label|term declaration>>A construct that establishes
an association between a particular variable, function, or type and its
attributes. (See <hlink|cppreference.com|https://en.cppreference.com/w/c/language/declarations>
<associate|func getchar|<tuple|1.2.1|?>>
<associate|func putchar|<tuple|3|?>>
<associate|ref includehelp-oct-hex|<tuple|1.1.1|?>>
- <associate|term declaration|<tuple|1.1|?>>
+ <associate|term declaration|<tuple|assignment|?>>
<associate|term definition|<tuple|declaration<label|term declaration>|?>>
<associate|term enumeration|<tuple|definition<label|term definition>|?>>
<associate|term escape_sequence|<tuple|enumeration<label|term