Last active
January 30, 2016 17:10
-
-
Save Wonicon/3fcbb841701aaf16eb2d to your computer and use it in GitHub Desktop.
find...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int main(int argc, char *argv[]) | |
{ | |
if (argc < 2) return -1; | |
FILE *fp = fopen(argv[1], "r"); | |
char linebuf[1024], head[] = "answer=\""; | |
while (fgets(linebuf, sizeof(linebuf), fp) != NULL) { | |
char *beg = linebuf; | |
while ((beg = strstr(beg, head)) != NULL) { | |
beg += sizeof(head) - 1; // Jump 'answer="' | |
char *end = strstr(beg, "\""); // Expect answer=".*" in one line (end shouldn't be null) | |
printf("%.*s\n", (int)(end - beg), beg); | |
beg = end + 1; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment