Commit Diff


commit - b84aabf0fc388ce5939a60bea982c4fad488dd84
commit + 4b5f1dbafa91a3f6e5bc3b252f2a046388059ca6
blob - 467b5390120da08d0eaa1bf122fbe0b3b7675910
blob + 3a531fb894eba3c84b592c57c990b672540067f2
--- 3-2-output
+++ 3-2-output
@@ -1 +1,129 @@
-_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
+_What maintains\tone\tVice,\twould\n
+_What maintains	one	Vice,	would
+
+\tbring\tup\ttwo\tChildren_. You may think     \n
+	bring	up	two	Children_. You may think     
+
+perhaps, that a _little_ Tea, or a _little_ Punch\n
+perhaps, that a _little_ Tea, or a _little_ Punch
+
+     now and\t\tthen, Diet a  \t    _little_ more\n
+     now and		then, Diet a  	    _little_ more
+
+   costly,\t  \tClothes a _little_    finer    \n
+   costly,	  	Clothes a _little_    finer    
+
+     , and a _little_\t\t     Entertainment now\t\t\t\n
+     , and a _little_		     Entertainment now			
+
+          and then, can be no _great_ Matter;    \t\t    \n
+          and then, can be no _great_ Matter;    		    
+
+but     remember what      _Poor Richard_ says, _Many a Little makes a Mickle._\n
+but     remember what      _Poor Richard_ says, _Many a Little makes a Mickle._
+
+\n
+
+
+_Bewareoflittleexpenses;AsmallLeakwillsinkagreatShip_;andagain,_WhoDaintieslove,shallBeggarsprove_;andmoreover,_FoolsmakeFeasts,andwiseMeneatthem._\n
+_Bewareoflittleexpenses;AsmallLeakwillsinkagreatShip_;andagain,_WhoDaintieslove,shallBeggarsprove_;andmoreover,_FoolsmakeFeasts,andwiseMeneatthem._
+
+\n
+
+
+         Buy   \twhat\t\t     thou\t\t    hast\n
+         Buy   	what		     thou		    hast
+
+ \t\t\t    no Need of,    \t\tand ere\t\tlong     thou     shalt\t\tsell thy Necessaries.  \t\t\t\n
+ 			    no Need of,    		and ere		long     thou     shalt		sell thy Necessaries.  			
+
+\n
+
+
+If you would know the Value of Money, go and try to borrow some; for, he that goes a borrowing goes a sorrowing.\n
+If you would know the Value of Money, go and try to borrow some; for, he that goes a borrowing goes a sorrowing.
+
+\n
+
+
+Andnowtoconclude,_ExperiencekeepsadearSchool,butFoolswilllearninnoother,andscarceinthat_;foritistrue,_wemaygiveAdvice,butwecannotgiveConduct_,as_PoorRichard_says:However,rememberthis,_Theythatwon'tbecounseled,can'tbehelped_,as_PoorRichard_says:andfarther,That_ifyouwillnothearReason,she'llsurelyrapyourKnuckles_.\n
+Andnowtoconclude,_ExperiencekeepsadearSchool,butFoolswilllearninnoother,andscarceinthat_;foritistrue,_wemaygiveAdvice,butwecannotgiveConduct_,as_PoorRichard_says:However,rememberthis,_Theythatwon'tbecounseled,can'tbehelped_,as_PoorRichard_says:andfarther,That_ifyouwillnothearReason,she'llsurelyrapyourKnuckles_.
+
+\n
+
+
+It would be thought a hard Government that should tax its People\n
+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\n
+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\n
+_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\n
+in absolute _Sloth_, or doing of nothing, with that which is spent in
+
+idle Employments or Amusements, that amount to nothing. _Sloth_, by\n
+idle Employments or Amusements, that amount to nothing. _Sloth_, by
+
+bringing on Diseases, absolutely shortens Life. _Sloth, like Rust,\n
+bringing on Diseases, absolutely shortens Life. _Sloth, like Rust,
+
+consumes faster than Labor wears; while the used key is always bright,\n
+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\n
+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\n
+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\n
+much more than is necessary do we spend in sleep, forgetting that _The
+
+sleeping Fox catches no Poultry_, and that _There will be sleeping\n
+sleeping Fox catches no Poultry_, and that _There will be sleeping
+
+enough in the Grave_, as _Poor Richard_ says.\n
+enough in the Grave_, as _Poor Richard_ says.
+
+\n
+
+
+_If Time be of all Things the most precious, wasting Time must be, as\n
+_If Time be of all Things the most precious, wasting Time must be, as
+
+Poor Richard_ says, _the_ _greatest Prodigality_; since, as he\n
+Poor Richard_ says, _the_ _greatest Prodigality_; since, as he
+
+elsewhere tells us, _Lost Time is never found again; and what we call\n
+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\n
+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\n
+doing, and doing to the Purpose; so by Diligence shall we do more with
+
+less Perplexity. _Sloth makes all Things difficult, but Industry all\n
+less Perplexity. _Sloth makes all Things difficult, but Industry all
+
+easy_, as _Poor Richard_ says; and _He that riseth late must trot all\n
+easy_, as _Poor Richard_ says; and _He that riseth late must trot all
+
+Day, and shall scarce overtake his Business at Night; while Laziness\n
+Day, and shall scarce overtake his Business at Night; while Laziness
+
+travels so slowly, that Poverty soon overtakes him_, as we read in\n
+travels so slowly, that Poverty soon overtakes him_, as we read in
+
+_Poor Richard_, who adds, _Drive thy Business, let not that drive\n
+_Poor Richard_, who adds, _Drive thy Business, let not that drive
+
+thee_; and _Early to Bed, and early to rise, makes a Man healthy,\n
+thee_; and _Early to Bed, and early to rise, makes a Man healthy,
+
+wealthy, and wise._\n
+wealthy, and wise._
+
blob - fd36b8b3b0e0646e3b9ddee4f3b9e235a3d34af9
blob + 312c1d34e005189d398c8b206f72fc4e1962fbc6
--- 3-2.c
+++ 3-2.c
@@ -18,8 +18,9 @@ int main() {
 	char output2[MAXLINE];
 	while ((len=getlin(input,MAXLINE))>0) {
 		escape(output, input);
-		printf("%s", output);
-//		snprintf(output2, MAXLINE, "%s", output);
+//		printf("%s\n", output);
+		unescape(output2, output);
+		printf("%s\n", output2);
 	}
 
 	return 0;
@@ -56,25 +57,21 @@ int escape(char s[], const char t[]) {
 
 /* 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]) {
+	int i, j;
+	for (i = 0, j = 0; t[j] != '\0'; i++, j++) {
+		switch (t[j]) {
 			case '\\': {
-				i++;
-				switch(t[i]) {
-					case 'n': s[j++] = '\n'; break;
-					case 't': s[j++] = '\t'; break;
-					default: s[j++] = t[i]; break;
+				j++;
+				switch(t[j]) {
+					case 'n': s[i] = '\n'; break;
+					case 't': s[i] = '\t'; break;
+					default: s[i] = t[j]; break;
 				}
-				i++;
 			} break;
-			default: s[j++] = t[i++]; break;
+			default: s[i] = t[j]; break;
 		};
 	}
-	s[j] = '\0';
-	return j;
+	s[i] = '\0';
+	return i;
 }
-*/