Skip to content

Instantly share code, notes, and snippets.

@nicolashohm
Created August 5, 2016 22:10
Show Gist options
  • Save nicolashohm/f6e50ddccb40ff95c05a9ccf64490472 to your computer and use it in GitHub Desktop.
Save nicolashohm/f6e50ddccb40ff95c05a9ccf64490472 to your computer and use it in GitHub Desktop.
find first set in file
#include<stdio.h>
int main(int argc, char *argv[]) {
printf("Start reading...\n");
FILE *fp = fopen(argv[1], "r");
int res = 0, buff = 0, ffs = 0, pos = 0;
while (fread(&buff, sizeof(int), 1, fp) == 1) {
ffs = __builtin_ffs(buff);
if (ffs > 0) {
printf("ffs at %d\n", pos+ffs);
break;
}
pos += sizeof(int);
}
printf("Scanned %d bytes\n", pos);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment