Commit Diff


commit - 11f8be0cd34b7f09a14494acd0c4cb8824f62819
commit + b84aabf0fc388ce5939a60bea982c4fad488dd84
blob - /dev/null
blob + aab284ab57515688f19377cda1779f77b8b71759 (mode 644)
--- /dev/null
+++ 3-2-input
@@ -0,0 +1,43 @@
+_What maintains	one	Vice,	would
+	bring	up	two	Children_. You may think     
+perhaps, that a _little_ Tea, or a _little_ Punch
+     now and		then, Diet a  	    _little_ more
+   costly,	  	Clothes a _little_    finer    
+     , and a _little_		     Entertainment now			
+          and then, can be no _great_ Matter;    		    
+but     remember what      _Poor Richard_ says, _Many a Little makes a Mickle._
+
+_Bewareoflittleexpenses;AsmallLeakwillsinkagreatShip_;andagain,_WhoDaintieslove,shallBeggarsprove_;andmoreover,_FoolsmakeFeasts,andwiseMeneatthem._
+
+         Buy   	what		     thou		    hast
+ 			    no Need of,    		and ere		long     thou     shalt		sell thy Necessaries.  			
+
+If you would know the Value of Money, go and try to borrow some; for, he that goes a borrowing goes a sorrowing.
+
+Andnowtoconclude,_ExperiencekeepsadearSchool,butFoolswilllearninnoother,andscarceinthat_;foritistrue,_wemaygiveAdvice,butwecannotgiveConduct_,as_PoorRichard_says:However,rememberthis,_Theythatwon'tbecounseled,can'tbehelped_,as_PoorRichard_says:andfarther,That_ifyouwillnothearReason,she'llsurelyrapyourKnuckles_.
+
+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.
+
+_If Time be of all Things the most precious, wasting Time must be, as
+Poor Richard_ says, _the_ _greatest Prodigality_; since, as he
+elsewhere tells us, _Lost Time is never found again; and what we call
+Time enough, always proves little enough_: Let us then up and be
+doing, and doing to the Purpose; so by Diligence shall we do more with
+less Perplexity. _Sloth makes all Things difficult, but Industry all
+easy_, as _Poor Richard_ says; and _He that riseth late must trot all
+Day, and shall scarce overtake his Business at Night; while Laziness
+travels so slowly, that Poverty soon overtakes him_, as we read in
+_Poor Richard_, who adds, _Drive thy Business, let not that drive
+thee_; and _Early to Bed, and early to rise, makes a Man healthy,
+wealthy, and wise._
blob - /dev/null
blob + 467b5390120da08d0eaa1bf122fbe0b3b7675910 (mode 644)
--- /dev/null
+++ 3-2-output
@@ -0,0 +1 @@
+_What maintains\tone\tVice,\twould\n\tbring\tup\ttwo\tChildren_. You may think     \nperhaps, that a _little_ Tea, or a _little_ Punch\n     now and\t\tthen, Diet a  \t    _little_ more\n   costly,\t  \tClothes a _little_    finer    \n     , and a _little_\t\t     Entertainment now\t\t\t\n          and then, can be no _great_ Matter;    \t\t    \nbut     remember what      _Poor Richard_ says, _Many a Little makes a Mickle._\n\n_Bewareoflittleexpenses;AsmallLeakwillsinkagreatShip_;andagain,_WhoDaintieslove,shallBeggarsprove_;andmoreover,_FoolsmakeFeasts,andwiseMeneatthem._\n\n         Buy   \twhat\t\t     thou\t\t    hast\n \t\t\t    no Need of,    \t\tand ere\t\tlong     thou     shalt\t\tsell thy Necessaries.  \t\t\t\n\nIf you would know the Value of Money, go and try to borrow some; for, he that goes a borrowing goes a sorrowing.\n\nAndnowtoconclude,_ExperiencekeepsadearSchool,butFoolswilllearninnoother,andscarceinthat_;foritistrue,_wemaygiveAdvice,butwecannotgiveConduct_,as_PoorRichard_says:However,rememberthis,_Theythatwon'tbecounseled,can'tbehelped_,as_PoorRichard_says:andfarther,That_ifyouwillnothearReason,she'llsurelyrapyourKnuckles_.\n\nIt would be thought a hard Government that should tax its People\none-tenth Part of their _Time_, to be employed in its Service. But\n_Idleness_ taxes many of us much more, if we reckon all that is spent\nin absolute _Sloth_, or doing of nothing, with that which is spent in\nidle Employments or Amusements, that amount to nothing. _Sloth_, by\nbringing on Diseases, absolutely shortens Life. _Sloth, like Rust,\nconsumes faster than Labor wears; while the used key is always bright,\nas Poor Richard says. But dost thou love Life, then do not squander\nTime, for that's the stuff Life is made of, as Poor Richard_ says. How\nmuch more than is necessary do we spend in sleep, forgetting that _The\nsleeping Fox catches no Poultry_, and that _There will be sleeping\nenough in the Grave_, as _Poor Richard_ says.\n\n_If Time be of all Things the most precious, wasting Time must be, as\nPoor Richard_ says, _the_ _greatest Prodigality_; since, as he\nelsewhere tells us, _Lost Time is never found again; and what we call\nTime enough, always proves little enough_: Let us then up and be\ndoing, and doing to the Purpose; so by Diligence shall we do more with\nless Perplexity. _Sloth makes all Things difficult, but Industry all\neasy_, as _Poor Richard_ says; and _He that riseth late must trot all\nDay, and shall scarce overtake his Business at Night; while Laziness\ntravels so slowly, that Poverty soon overtakes him_, as we read in\n_Poor Richard_, who adds, _Drive thy Business, let not that drive\nthee_; and _Early to Bed, and early to rise, makes a Man healthy,\nwealthy, and wise._\n
\ No newline at end of file
blob - /dev/null
blob + fd36b8b3b0e0646e3b9ddee4f3b9e235a3d34af9 (mode 644)
--- /dev/null
+++ 3-2.c
@@ -0,0 +1,80 @@
+/* 3-2 Write a function escape(s,t) that converts characters like newline and
+ * tab into visible escape sequences like \n and \t as it copies the string t
+ * to s. Use a switch. Write a function for the other direction as well,
+ * converting escape sequences into the real characters. */
+
+#include <stdio.h>
+
+#define MAXLINE 1000		/* maximum input line size */
+
+int escape(char s[], const char t[]);
+int getlin(char s[], int lim);
+int unescape(char s[], const char t[]);
+
+int main() {
+	int len;
+	char input[MAXLINE];
+	char output[MAXLINE];
+	char output2[MAXLINE];
+	while ((len=getlin(input,MAXLINE))>0) {
+		escape(output, input);
+		printf("%s", output);
+//		snprintf(output2, MAXLINE, "%s", output);
+	}
+
+	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;
+}
+
+/* escape: copies string t to s while converting characters into escape
+ * sequences; return length of string s */
+int escape(char s[], const char t[]) {
+	int i, j;
+	for (i = 0, j = 0; t[j] != '\0'; i++, j++) {
+		switch (t[j]) {
+			case '\t': s[i++] = '\\'; s[i] = 't'; break;
+			case '\n': s[i++] = '\\'; s[i] = 'n'; break;
+			default: s[i] = t[j]; break;
+		};
+	}
+	s[i] = '\0';
+	return i;
+}
+
+/* unescape: copies string t to s while converting escape sequences into
+ * newlines and tabs; return length of string s */
+/*
+int unescape(char s[], const char t[]) {
+	int i = 0;
+	int j = 0;
+	while (t[i] != '\0') {
+		switch (t[i]) {
+			case '\\': {
+				i++;
+				switch(t[i]) {
+					case 'n': s[j++] = '\n'; break;
+					case 't': s[j++] = '\t'; break;
+					default: s[j++] = t[i]; break;
+				}
+				i++;
+			} break;
+			default: s[j++] = t[i++]; break;
+		};
+	}
+	s[j] = '\0';
+	return j;
+}
+*/