commit - 780d1efacde062921b1045a3f5f84bf54f7ab231
commit + 5a3cc2ca160febcfc5fc81eb508016154cce2510
blob - /dev/null
blob + cc674d1201c2d70142a3a85a27bd0bf20d71df14 (mode 644)
--- /dev/null
+++ 1-19-output
+INPUT:
+
+It would be thought a hard Government that should tax its People
+one-tenth Part of their _Time_, to be employed in its Service. But
+_Idleness_ taxes many of us much more, if we reckon all that is spent
+in absolute _Sloth_, or doing of nothing, with that which is spent in
+idle Employments or Amusements, that amount to nothing. _Sloth_, by
+bringing on Diseases, absolutely shortens Life. _Sloth, like Rust,
+consumes faster than Labor wears; while the used key is always bright,
+as Poor Richard says. But dost thou love Life, then do not squander
+Time, for that's the stuff Life is made of, as Poor Richard_ says. How
+much more than is necessary do we spend in sleep, forgetting that _The
+sleeping Fox catches no Poultry_, and that _There will be sleeping
+enough in the Grave_, as _Poor Richard_ says.
+
+OUTPUT:
+
+elpoeP sti xat dluohs taht tnemnrevoG drah a thguoht eb dluow tI¿»ï
+tuB .ecivreS sti ni deyolpme eb ot ,_emiT_ rieht fo traP htnet-eno
+tneps si taht lla nokcer ew fi ,erom hcum su fo ynam sexat _sseneldI_
+ni tneps si hcihw taht htiw ,gnihton fo gniod ro ,_htolS_ etulosba ni
+yb ,_htolS_ .gnihton ot tnuoma taht ,stnemesumA ro stnemyolpmE eldi
+,tsuR ekil ,htolS_ .efiL snetrohs yletulosba ,sesaesiD no gnignirb
+,thgirb syawla si yek desu eht elihw ;sraew robaL naht retsaf semusnoc
+rednauqs ton od neht ,efiL evol uoht tsod tuB .syas drahciR rooP sa
+woH .syas _drahciR rooP sa ,fo edam si efiL ffuts eht s'taht rof ,emiT
+ehT_ taht gnittegrof ,peels ni dneps ew od yrassecen si naht erom hcum
+gnipeels eb lliw erehT_ taht dna ,_yrtluoP on sehctac xoF gnipeels
+.syas _drahciR rooP_ sa ,_evarG eht ni hguone
blob - /dev/null
blob + 3765955a0b0ef9ad9a407eb16f0ea1a71657817b (mode 644)
--- /dev/null
+++ 1-19-text
+It would be thought a hard Government that should tax its People
+one-tenth Part of their _Time_, to be employed in its Service. But
+_Idleness_ taxes many of us much more, if we reckon all that is spent
+in absolute _Sloth_, or doing of nothing, with that which is spent in
+idle Employments or Amusements, that amount to nothing. _Sloth_, by
+bringing on Diseases, absolutely shortens Life. _Sloth, like Rust,
+consumes faster than Labor wears; while the used key is always bright,
+as Poor Richard says. But dost thou love Life, then do not squander
+Time, for that's the stuff Life is made of, as Poor Richard_ says. How
+much more than is necessary do we spend in sleep, forgetting that _The
+sleeping Fox catches no Poultry_, and that _There will be sleeping
+enough in the Grave_, as _Poor Richard_ says.
blob - /dev/null
blob + 316f47d05d2ce95d0e60f80b328dd2b059e2f7ef (mode 644)
--- /dev/null
+++ 1-19.c
+/* 1-19 Write a function reverse(s) that reverses the character string s. Use
+ it to write a program that reverses its input a line at a time. */
+
+#include <stdio.h>
+
+#define MAXLINE 1000 /* maximum input line size */
+
+int getlin(char line[], int maxline);
+void reverse(char s[]);
+int length(char s[]);
+
+int main() {
+ int len; /* current line length */
+ char line[MAXLINE]; /* current input line */
+
+ while ((len = getlin(line, MAXLINE)) > 0) {
+ reverse(line);
+ printf("%s", line);
+ }
+ return 0;
+}
+
+/* getlin: read a line into s, return length */
+int getlin(char s[], int lim) {
+ int c, i;
+
+ for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
+ s[i] = c;
+ if (c == '\n') {
+ s[i] = c;
+ ++i;
+ }
+ s[i] = '\0';
+ return i;
+}
+
+/* length: returns the length of character string s */
+int length(char s[]) {
+ int i = 0;
+ while (s[i] != '\0')
+ i++;
+ return i;
+}
+
+/* reverse: reverses the character string s */
+void reverse(char s[]) {
+ char temp;
+ int i = 0;
+ int j = length(s) - 1;
+ /* don't reverse newline */
+ if (s[j] == '\n')
+ j--;
+ for (; i < j; i++, j--) {
+ temp = s[i];
+ s[i] = s[j];
+ s[j] = temp;
+ }
+}
blob - /dev/null
blob + a07c8fabfb78cd087ef005abf009b4772cec9236 (mode 644)
--- /dev/null
+++ 1-20.c
+/* 1-20 Write a program detab that replaces tabs in the input with the proper
+ * number of blanks to space to the next tab stop. Assume a fixed set of tab
+ * stops, say every n columns. Should n be a variable or a symbolic parameter?
+ * */
+
+#include <stdio.h>
+
+#define MAXLINE 1000 /* maximum input line size */
+
+int getlin(char line[], int maxline);
+void reverse(char s[]);
+int length(char s[]);
+
+int main() {
+ int len; /* current line length */
+ char line[MAXLINE]; /* current input line */
+
+ while ((len = getlin(line, MAXLINE)) > 0) {
+ reverse(line);
+ printf("%s", line);
+ }
+ return 0;
+}
+
+/* getlin: read a line into s, return length */
+int getlin(char s[], int lim) {
+ int c, i;
+
+ for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
+ s[i] = c;
+ if (c == '\n') {
+ s[i] = c;
+ ++i;
+ }
+ s[i] = '\0';
+ return i;
+}
+
+/* length: returns the length of character string s */
+int length(char s[]) {
+ int i = 0;
+ while (s[i] != '\0')
+ i++;
+ return i;
+}
+
+/* reverse: reverses the character string s */
+void reverse(char s[]) {
+ char temp;
+ int i = 0;
+ int j = length(s) - 1;
+ /* don't reverse newline */
+ if (s[j] == '\n')
+ j--;
+ for (; i < j; i++, j--) {
+ temp = s[i];
+ s[i] = s[j];
+ s[j] = temp;
+ }
+}