Commit Diff


commit - 7c3c7462d4897d03babd7863e1df9ab6ad1b692e
commit + c0524b21c58b6c724a07074d102b99d45e14b194
blob - /dev/null
blob + e6c4d8d04e1da10c48cafda869f63994f67a8a74 (mode 644)
--- /dev/null
+++ 4-1-input
@@ -0,0 +1,20 @@
+Then I walked up the street, gazing about till near the market-house I met a boy with bread.
+street
+Then I walked up the street, gazing about till near the market-house I met a boy with bread.
+gazed
+Then I walked up the street, gazing about till near the market-house I met a boy with bread.
+gazing
+I had made many a meal on bread, and, inquiring where he got it, I went immediately to the baker's he directed me to, in Second-street, and ask'd for bisket, intending such as we had in Boston; but they, it seems, were not made in Philadelphia. Then I asked for a three-penny loaf, and was told they had none such.
+and
+I had made many a meal on bread, and, inquiring where he got it, I went immediately to the baker's he directed me to, in Second-street, and ask'd for bisket, intending such as we had in Boston; but they, it seems, were not made in Philadelphia. Then I asked for a three-penny loaf, and was told they had none such.
+ask
+I had made many a meal on bread, and, inquiring where he got it, I went immediately to the baker's he directed me to, in Second-street, and ask'd for bisket, intending such as we had in Boston; but they, it seems, were not made in Philadelphia. Then I asked for a three-penny loaf, and was told they had none such.
+ to
+I had made many a meal on bread, and, inquiring where he got it, I went immediately to the baker's he directed me to, in Second-street, and ask'd for bisket, intending such as we had in Boston; but they, it seems, were not made in Philadelphia. Then I asked for a three-penny loaf, and was told they had none such.
+such.
+I had made many a meal on bread, and, inquiring where he got it, I went immediately to the baker's he directed me to, in Second-street, and ask'd for bisket, intending such as we had in Boston; but they, it seems, were not made in Philadelphia. Then I asked for a three-penny loaf, and was told they had none such.
+he
+So not considering or knowing the difference of money, and the greater cheapness nor the names of his bread, I bade him give me three-penny worth of any sort. He gave me, accordingly, three great puffy rolls. I was surpris'd at the quantity, but took it, and, having no room in my pockets, walk'd off with a roll under each arm, and eating the other.
+and
+Thus I went up Market-street as far as Fourth-street, passing by the door of Mr. Read, my future wife's father; when she, standing at the door, saw me, and thought I made, as I certainly did, a most awkward, ridiculous appearance.
+,
blob - /dev/null
blob + d331ba94a3f926f06d38c6462e2afd2a37a6ef94 (mode 644)
--- /dev/null
+++ 4-1-output
@@ -0,0 +1,10 @@
+street found at index 21
+gazed found at index -1
+gazing found at index 29
+and found at index 282
+ask found at index 252
+ to found at index 289
+such. found at index 309
+he found at index 296
+and found at index 329
+, found at index 206
blob - /dev/null
blob + 07da1a542a54e306ed1bd1e200aaf415139f7470 (mode 644)
--- /dev/null
+++ 4-1.c
@@ -0,0 +1,41 @@
+/* 4-1 Write the function strrindex(s,t) which returns the position of the
+ * rightmost occurrence of t in s, or -1 if there is none. */
+
+#include <stdio.h>
+#include <string.h>
+
+#define MAXLINE 1000            /* maximum input line size */
+
+int strrindex(char s[], char t[]);
+int getlin(char line[], int maxline);
+
+int main() {
+	char s[MAXLINE];
+	char t[MAXLINE];
+	while(getlin(s, MAXLINE) > 0 && getlin(t, MAXLINE) > 0) {
+		printf("%s found at index %d\n", t, strrindex(s, t));
+	}
+	return 0;
+}
+
+/* strrindex: return index of rightmost t in s, or -1 if none. */
+int strrindex(char s[], char t[]) {
+	int i, j, k;
+	for (i = strlen(s)-1; i >= 0; i--) {
+		for (j = 0; s[i+j] == t[j]; j++)
+				;
+		if (t[j] == '\0')
+			return i;
+	}
+	return -1;
+}
+
+/* getlin: read a line into s, return length; modified to trim ending newline */
+int getlin(char s[], int lim) {
+	int c, i;
+
+	for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
+		s[i] = c;
+	s[i] = '\0';
+	return i;
+}