aboutsummaryrefslogtreecommitdiff
path: root/src/strstreamone.c
diff options
context:
space:
mode:
authorCalvin Morrison <mutantturkey@gmail.com>2014-01-17 14:28:49 -0500
committerCalvin Morrison <mutantturkey@gmail.com>2014-01-17 14:28:49 -0500
commitb09eecbec7e7cca1c133ba5923f55713cf7a78cf (patch)
tree6ff08efad3b5dcd2aef32905b4637625d6c8d6ea /src/strstreamone.c
parentecc00aae08c06ae2da5629533ef69d7c5ffd86fe (diff)
update makefile and make a src directory
Diffstat (limited to 'src/strstreamone.c')
-rw-r--r--src/strstreamone.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/strstreamone.c b/src/strstreamone.c
new file mode 100644
index 0000000..68da309
--- /dev/null
+++ b/src/strstreamone.c
@@ -0,0 +1,43 @@
+// find string in
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(int argc, char **argv){
+
+ char buffer[BUFSIZ] = { 0 };
+ char *buf, *start;
+ ssize_t len = 0;
+
+ int cpy = 0;
+
+ unsigned long long pos = 0;
+ unsigned long long cpy_size = 0;
+
+ // get max argument length
+ int save_size = strlen(argv[1]);
+
+ cpy = save_size - 1;
+ cpy_size = BUFSIZ - cpy;
+
+ buf = buffer;
+ start = buf + cpy;
+
+ // copy our first cpy length into the first part of our buffer
+ len = fread(buffer, 1, cpy, stdin);
+ if(len == 0)
+ exit(EXIT_FAILURE);
+
+ // read into "start" (buf + cpy) from stdin
+ while((len = fread(start, 1, cpy_size, stdin)) != 0) {
+ char *p = buffer;
+ while((p = strstr(p, argv[1])) != NULL) {
+ printf("%llu\n", pos + (p - buffer));
+ p++;
+ }
+ memcpy(buffer, buffer + len, cpy);
+ pos = pos + len;
+ }
+ return 0;
+}