commit - 823701b65733bcdbf9b5e617978d845ce46e20b0
commit + 7c3c7462d4897d03babd7863e1df9ab6ad1b692e
blob - /dev/null
blob + 1b3c55d6b8230d3b4e49e9c7350c7e084cc95cd6 (mode 644)
--- /dev/null
+++ 2-10-input
+AUTOBIOGRAPHY OF BENJAMIN FRANKLIN
+
+WITH ILLUSTRATIONS _by_ E. BOYD SMITH
+
+EDITED _by_ FRANK WOODWORTH PINE
+
+[Illustration: Printers Mark]
+
+_New York_ HENRY HOLT AND COMPANY 1916
+
+Copyright, 1916,
+
+BY HENRY HOLT AND COMPANY
+
+June, 1922
+
+THE QUINN & BODEN CO. PRESS RAHWAY, N. J.
+
+CONTENTS
+...
+I should have called my book The Art of Virtue,[72] because
+it would have shown the means and manner of obtaining virtue, which
+would have distinguished it from the mere exhortation to be good, that
+does not instruct and indicate the means, but is like the apostle's
+man of verbal charity, who only without showing to the naked and
+hungry how or where they might get clothes or victuals, exhorted them
+to be fed and clothed.--James ii. 15, 16.
blob - /dev/null
blob + cb15badbde187cdb9ac698bb0c40d9d832b4a71b (mode 644)
--- /dev/null
+++ 2-10-output
+autobiography of benjamin franklin
+
+with illustrations _by_ e. boyd smith
+
+edited _by_ frank woodworth pine
+
+[illustration: printers mark]
+
+_new york_ henry holt and company 1916
+
+copyright, 1916,
+
+by henry holt and company
+
+june, 1922
+
+the quinn & boden co. press rahway, n. j.
+
+contents
+...
+i should have called my book the art of virtue,[72] because
+it would have shown the means and manner of obtaining virtue, which
+would have distinguished it from the mere exhortation to be good, that
+does not instruct and indicate the means, but is like the apostle's
+man of verbal charity, who only without showing to the naked and
+hungry how or where they might get clothes or victuals, exhorted them
+to be fed and clothed.--james ii. 15, 16.
blob - /dev/null
blob + 9556727bfab0d4a34f8bc19bdbca2587badd87ac (mode 644)
--- /dev/null
+++ 2-10.c
+/* 2-10 Rewrite the function lower, which converts upper case letters to lower
+ * case, with a conditional expression instead of if-else.
+ */
+
+#include <stdio.h>
+
+int getlin(char line[], int maxline);
+int lower(int c);
+
+int main() {
+ int c;
+ while ((c=getchar()) != EOF) {
+ putchar(lower(c));
+ }
+ return 0;
+}
+
+/* lower: convert c to lower case; ASCII only */
+int lower(int c) {
+ return (c >= 'A' && c <= 'Z') ? c + 'a' - 'A': c;
+}
blob - /dev/null
blob + 78a7ac027cdc2d6ce085393a1d85a2a2d4d86be5 (mode 644)
--- /dev/null
+++ 3-6-input
+2147483647 10
+-2147483647 10
+5954 3
+6475 4
+2558 5
+10579 6
+28149 7
+26450 8
+4280 9
+3402 10
+8696 9
+30072 8
+29591 7
+7140 6
+14924 5
+28854 4
+22352 3
blob - /dev/null
blob + d4fac98f3cb31480d30df460404086f88b7852d9 (mode 644)
--- /dev/null
+++ 3-6-output
+2147483647
+-2147483647
+5954
+6475
+ 2558
+ 10579
+ 28149
+ 26450
+ 4280
+ 3402
+ 8696
+ 30072
+ 29591
+ 7140
+14924
+28854
+22352
blob - /dev/null
blob + e57e0c50be035b4345710f7cf9d5a44269d6a360 (mode 644)
--- /dev/null
+++ 3-6.c
+/* 3-6 Write a version of itoa that accepts three arguments instead of two. The
+ * third argument is a minimum field width; the converted number must be padded
+ * with blanks on the left if necessary to make it wide enough. */
+
+#include <stdio.h>
+#include <string.h>
+
+#define MAXLINE 1000 /* maximum input line size */
+
+void itoa(int n, char s[], int width);
+void reverse(char s[]);
+
+int main() {
+ int i, width;
+ char line[MAXLINE];
+
+ while (scanf("%d %d\n", &i, &width) == 2) {
+ itoa(i, line, width);
+ printf("%s\n", line);
+ }
+
+ return 0;
+}
+
+/* itoa: convert n to characters in s padded on left to minimum width width*/
+void itoa(int n, char s[], int width) {
+ int i, sign;
+
+ if ((sign = n) < 0) /* record sign */
+ n = -n; /* make n positive */
+ i = 0;
+ do { /* generate digits in reverse order */
+ s[i++] = n % 10 + '0'; /* get next digit */
+ } while ((n /= 10) > 0);
+ if (sign < 0)
+ s[i++] = '-';
+ while (i < width) /* left-pad to minimum width */
+ s[i++] = ' ';
+ s[i] = '\0';
+ reverse(s);
+}
+
+/* reverse: reverse string s in place */
+void reverse(char s[]) {
+ int c, i, j;
+ for (i = 0, j = strlen(s)-1; i < j; i++, j--) {
+ c = s[i], s[i] = s[j], s[j] = c;
+ }
+}