Skip to content

Instantly share code, notes, and snippets.

@Wonicon
Last active January 30, 2016 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wonicon/3fcbb841701aaf16eb2d to your computer and use it in GitHub Desktop.
Save Wonicon/3fcbb841701aaf16eb2d to your computer and use it in GitHub Desktop.
find...
#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